where do all digits come from? I am using FOP 1.0
How can I avoid that?
This is a problem of floating point arithmetics:
If your data have at maximum 3 decimal digits, then you can avoid the problem by multiplying your numbers by 1000
thus making them integers and then adding them and dividing the end result by 1000 to get the end result.
Thanks for your suggestion. I am not really an XSL expert, just new to it.
I have the feeling it doesn't give much flexibility to manipulate the paths.
I did this:
<xsl:value-of select="sum (key('groupBycategory', concat(subscriptionAttributes[parameter='CATEGORY_NAME_FR']/value,../../../accountName))/totalAmount * 1000)" />
<xsl:value-of select="($totamnt) div 1000" />
And got this error: Can not convert #NUMBER to a Nodelist. See picture
I guess it's the issue of SUM (function()) which is not allowed and maybe I have to call a function passing whole path as variable.? Not sure
I have recreated your issue here:
with xmldata(xmlval) as ( select xmltype( '<Values> <Val>1.190</Val> <Val>1.190</Val> <Val>1.190</Val> <Val>1.190</Val> <Val>1.190</Val> </Values>') from dual) select xmlcast(xmlquery('sum(/Values/Val * 1000)' passing xmlval returning content) as float) as result from xmldata XVM-01004: [XPTY0004] Expression type does not match a required type
The problem is that /Values/Val represents a nodelist, as your error message says and you can't multiply a nodelist with a number.
The fix is to loop over the nodelist:
select xmlcast(xmlquery('sum(for $v in /Values/Val return $v * 1000)' passing xmlval returning content) as float) / 1000 as result from xmldata RESULT ------- 5.95000
cormaco Thank you for the sample code and explanation.
I understand the logic but I see that you are using SQL query on XML data. But in my case I am working purely with XSL code, so I cannot do things like:
sum (for each .....) which is the equivalent of your sum(for $v in /Values/Val return $v * 1000)
So alternatively, I am trying this technic of passing the whole nodelist as parameter to a function that loops through itself...(found here on forum)
<xsl:variable name="prem" select="$liste/totalAmount"/>
<xsl:value-of select="$prem" />
<xsl:with-param name="liste" select="$liste[position()!=1]"/>
<xsl:value-of select="$firstVal + $reste"/>
Unfortunately, this is costly when the XML has a lot of data meaning the processing time gets longer and sometimes system aborts....
Anyway, I have to assign correct answer to your suggestion