on 01-23-2008 9:01 AM
Hi All,
I am stuck in finding sum of variables using XSLT.
I have a field D_Txt which is series of numbers separated by spaces under S_Txt ( S_Txt can repeat).
I need to get the sum of first numbers(Numbers before first space) in all D_Txt that can repeat whenever S_Txt repeat.
<xsl:variable name="tot" /> (global declaration)
<xsl:template match="/">
<xsl:for-each select="Root/S_Txt>
.........
..........
<xsl:variable name="x" select="substring-before(D_Txt,' ')"/>
<xsl:variable name="tot" select="$tot + $x"/>
</xsl:for-each>
Total is: <xsl:value-of select="$tot"/>
</xsl:template>
With the above code I get the 'tot' value as NaN. When I am assigning "0" to 'tot' variable, each time when loop repeats "0" is getting assigned to 'tot' variable. But I need the sum of all values that comes in 'x' variable.
Can you resolve this problem.
With Regards,
Lakshmi.
Edited by: Venkata Lakshmi Kante on Jan 23, 2008 10:02 AM
Hi
refer these two links :
/people/aashish.sinha/blog/2008/01/17/step-150-by-150-step-simple-approach-for-xslt-mapping
/people/aashish.sinha/blog/2008/01/21/xslt-mapping-for-multiple-segments-of-xml
regards
Aashish Sinha
PS : reward points if helpful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lakshmi,
a variable in XSLT is NOT a variable in programmatic sense.
In XSLT you can only apply a value to a variable ONCE!
If a value is applied you cannot change it!
But I am sure you could solve your problem using a recursion
http://www.ibm.com/developerworks/xml/library/x-xslrecur/
Regards Mario
Edited by: Mario Müller on Jan 23, 2008 6:09 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.