In my env i am making two calls to get account details from different organization, and both organization return account details, but they are adding extra leading zeros in accountNumber, so my code is failing when i am comparing request and response account numbers, Is there any way to remove extra zeros from below xml using xslt.
<EAI>
<SvcRS>
<accountHeader>
<errorHost>orgA</errorHost>
</accountHeader>
<accoutnDetails>
<accountNumber>0000000111118800</accountNumber>
<accountType>credit</accountType>
<errorDetails>
<code>111</code>
<description>Account is not valid</description>
</errorDetails>
</accoutnDetails>
</SvcRS>
<SvcRS>
<accountHeader>
<errorHost>orgB</errorHost>
</accountHeader>
<accoutnDetails>
<accountNumber>000111118800</accountNumber>
<accountType>credit</accountType>
<errorDetails>
<code>0001</code>
<description>Not enough balance</description>
</errorDetails>
</accoutnDetails>
</SvcRS>
</EAI>
Thanks,
You can use format-number function as below:
<xsl:value-of select="format-number(.//accountNumber, '#')"/>
Result:
111118800
In XSLT 2 or later you can use replace(., '^0+', '') in the context of xsl:template match="accountNumber" to remove leading zeros with string operations (http://xsltfiddle.liberty-development.net/3Nqn5Y3/1) or you can use xs:integer(.) to remove the leading zeros by converting that value inside of element to an integer (http://xsltfiddle.liberty-development.net/3Nqn5Y3).
Related
The output below is expected. Given the xslt is sorted by SHIPPEDQTYPALLETNR
The Output xml below
<ORDER_DATA_Main>
<ORDER_DATA>
<SHIPPEDQTYPALLETNR>97915</SHIPPEDQTYPALLETNR>
<MASTER_P>0001</MASTER_P>
</ORDER_DATA>
<ORDER_DATA>
<SHIPPEDQTYPALLETNR>97916</SHIPPEDQTYPALLETNR>
<MASTER_P>0002</MASTER_P>
</ORDER_DATA>
<ORDER_DATA>
<SHIPPEDQTYPALLETNR>97917</SHIPPEDQTYPALLETNR>
<MASTER_P>0003</MASTER_P>
</ORDER_DATA>
</ORDER_DATA_Main>
xml file
<ORDER_DATA>
<ORDER_P>
<ORDER_QUANTITY>
<SKU_INFO>
<TQTY>260</TQTY>
</SKU_INFO>
<SHIPPED_GOODS_INFO_HEADER>
<SHIPPED_GOODS_INFO>
<CONTRYOFORIGIN>US</CONTRYOFORIGIN>
<SHIPPEDQTYPALLETNR>97916</SHIPPEDQTYPALLETNR>
</SHIPPED_GOODS_INFO>
<MASTER_PALETTE>
<MASTER_P>0002</MASTER_P>
</MASTER_PALETTE>
</SHIPPED_GOODS_INFO_HEADER>
</ORDER_QUANTITY>
</ORDER_P>
<ORDER_P>
<ORDER_QUANTITY>
<SKU_INFO>
<TQTY>250</TQTY>
</SKU_INFO>
<SHIPPED_GOODS_INFO_HEADER>
<SHIPPED_GOODS_INFO>
<CONTRYOFORIGIN>US</CONTRYOFORIGIN>
<SHIPPEDQTYPALLETNR>97915</SHIPPEDQTYPALLETNR>
</SHIPPED_GOODS_INFO>
<MASTER_PALETTE>
<MASTER_P>0001</MASTER_P>
</MASTER_PALETTE>
</SHIPPED_GOODS_INFO_HEADER>
</ORDER_QUANTITY>
</ORDER_P>
</ORDER_DATA>
below xslt snippet
xsltsnippet
xsltcode
<MASTER_P>
<xsl:value-of select="//MASTER_PALETTE[//SHIPPED_GOODS_INFO/SHIPPEDQTYPALLETNR=$v_pallett]/MASTER_P"/>
</MASTER_P>
MASTER_PALETTE and SHIPPED_GOODS_INFO are siblings. When you write
select="//MASTER_PALETTE[//SHIPPED_GOODS_INFO...]
the // within the predicate means the predicate will be true if any SHIPPED_GOODS_INFO anywhere in the document satisfies the conditions, regardless whether it is related in any way to the MASTER_PALETTE being tested. Instead of // here, try ../.
I am using tinyxpath-1.3.1. C/C++ on Linux. When I do a xpath search on a document I am not finding nodes when I think I should.
My XML:
<data>
<event deviceId="25479545.5" interface="sensor-multilevel"
command="state" label="luminance" newValue="800"
oldValue="9" time="1412227484" />
</data>
My xpath Expression:
/data/event[#deviceId="25479545.5" and #interface="sensor-multilevel" and
#label="luminance" and #newValue>600 and #oldValue<10]
If I take the oldValue out and use () like this the comparison works:
/data/event[(#deviceId="25479545.5" and #interface="sensor-multilevel") and
(#label="luminance" and #newValue>600)]
Is there some limit on the number of comparisons?
Anything special with converting the 600 to a decimal?
Do I need to "" the value 600, it seems to work either way.
Any ideas on how to get it to work with the oldValue attribute included in the expression?
TinyXPath call:
TiXmlNode * node = TinyXPath::XNp_xpath_node( root, expression.c_str() );
Thanks
Larry
You seem to be getting a string comparison here rather than a numeric comparison ("9" > "10" in alphabetic order). That's incorrect according to the specs (both XPath 1.0 and 2.0, though they get there in rather different ways).
The safest approach is probably to convert explicitly to a number: write
number(#oldValue) < 10
Looks like the tinyxpath library has some bugs....
This works for tinyxpath-1.3.1:
/data/event[((#deviceId="25479545.5" and #interface="sensor-multilevel") and
(#label="luminance" and #newValue>"600")) and (#oldValue<"10")]
parenthesis were needed to group these in a final set of 2.
Or I just convert to using libxml2.
Below is the xml. Now I am looking for an xslt where in the first loop of <ns0:EBLoop1> when EB01 = 1 then I need to get the value of <EB05>PACKAGE A STANDARD PLAN</EB05> in the next EBLoop1.
How can I do this.
<ns0:EBLoop1>
<ns0:EB>
<EB01>1</EB01>
<EB05>This</EB05>
<EB07>0</EB07>
</ns0:EB>
<ns0:MSG>
<MSG01>Please See the Provider Manual</MSG01>
</ns0:MSG>
</ns0:EBLoop1>
<ns0:EBLoop1>
<ns0:EB>
<EB01>D</EB01>
<EB05>PACKAGE A STANDARD PLAN</EB05>
<EB07>0</EB07>
</ns0:EB>
</ns0:EBLoop1>
<ns0:EBLoop1>
<ns0:EB>
<EB01>F</EB01>
<EB03>30</EB03>
<EB07>0</EB07>
</ns0:EB>
</ns0:EBLoop1>
Thanks,
Gopi
Assuming the context node is your EBLoop1 element, you can get the next one with xpath:
../following-sibling::ns:EBLoop1[1]/ns:EB/EB05
But you need to define your namespace and make use of the prefix in your xpath.
I am dealing with some auto-generated XSLT code.
It contains the following:
string(string(.))
number(string(.))
string(number(string(.)))
Is there any point to these? Or are they reducible to
string(.)
number(.)
string(.)
?
Like Martin says.
There are edge cases in XPath 2.0 where number(string(.)) is not exactly the same as number(.), for example if the context item is an instance of xs:gYear then number(.) will fail but number(string(.)) will succeed; contrariwise, if the context item is a boolean, number(.) will convert true to 1 and false to 0, while number(string(.)) converts both to NaN. But it's very unlikely that these edge cases are important to your application.
For the first one I am pretty sure it can be reduced to string(.). For the third one I don't think you can reduce it to string(.) as for instance for the context node having a character as its string content (e.g. <foo>a</foo>) doing number(string(.)) gives you the special number value "not a number" and if you do string() on that again you get (http://www.w3.org/TR/xpath/#section-Number-Functions, http://www.w3.org/TR/xpath/#section-String-Functions) the string "NaN". I am not sure about the second being reducible, maybe you can check the details of edge cases with the links I provided.
I'm having some trouble with displaying numbers in apex, but only when i fill them in through code. When numbers are fetched through an automated row fetch, they're fine!
Leading Zero
For example, i have a report where a user can click a link, which runs a javascript function. There i get detailed values for that record through an application process. The returned values are in JSON. Several fields are number fields.
My response looks as follows (fe):
{"AVAILABLE_STOCK": "15818", "WEIGHT": ".001", "VOLUME": ".00009", "BASIC_PRICE": ".06", "COST_PRICE": ".01"}
Already the numbers here 'not correct': values less than one do not have a zero before the .
I kind of hoped that the format mask on the items would catch this. If i specify FM999G990D000 for the item weight, i'd expect it to show '0.001' .
But okay, i suppose it only works that way when it comes through session state, and not when you set an item value through $("#").val() ?
Where do i go wrong? Is my only option to change my select in the app process?
Now:
SELECT '"AVAILABLE_STOCK": "' || AVAILABLE_STOCK ||'", '||
'"WEIGHT": "' || WEIGHT ||'", '||
'"VOLUME": "' || VOLUME ||'", '||
'"BASIC_PRICE": "' || BASIC_PRICE ||'", '||
Do i need to provide my numberfields a to_char with the format mask here (to_char(available_stock, 'FM999G990D000')) ?
Right now i need to put my numbers between quotes ofcourse, or i get invalid json when i parse it.
Trailing Zero
I have an application process on a page on the after header point, right after an automated row fetch. Several fields are calculated here (totals). The variables used are all specified as number(10, 2). All values are correct and rounded to 2 values after the comma. My format masks on the items are also specified as FM999G999G990D00.
However, when one of the calculated values has only one meaningfull value after the comma, the trailing zeros get dropped. Instead of '987.50', it is displayed as '987.5'.
So, i have a number variable, and assign it like this: :P12_NDB_TOTAL_INCL := v_totI;
Would i need to convert my numbers here too, with format mask?
What am i doing wrong, or what am i missing?
If you aren't doing math on it and are more concerned with formatting, I suggest treating it as a varchar/string instead of as a number wherever you can.