Hello and please help.
I'm new to XSL and how can i calculate the running total and display it within the for loop.
part of my XML
<Expenses>
<expense> <id>1</id><amount>10</amount></expense>
<expense> <id>1</id><amount>20</amount></expense>
<expense> <id>1</id><amount>30</amount></expense>
.....
</expenses>
my XSL
<xsl:template match="/">
...
<xsl:for-each select="expenses/expense">
<tr><td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="amount"/></td>
<!-- here is the running total of the amount ????? -->
<xsl:variable name="temp" select="sum(preceding-sibling::expenses/expense/amount) + amount"/>
<td><xsl:value-of select="$temp"/></td>
<tr>
</xsl:for-each>....
and it gives
<tr><td>1</td><td>10</td><td>10</td></tr>
<tr><td>2</td><td>20</td><td>20</td></tr>
<tr><td>2</td><td>20</td><td>30</td></tr> ...
instead of
<tr><td>1</td><td>10</td><td>10</td></tr>
<tr><td>2</td><td>20</td><td>30</td></tr>
<tr><td>2</td><td>20</td><td>60</td></tr>...
What did i do wrong? or how ca i implement something similar to the following VB code in XSL
A= 0
for (i=1 to 10)
a = a + somevalue
' display a
next i
Thank you
I'm new to XSL and how can i calculate the running total and display it within the for loop.
part of my XML
<Expenses>
<expense> <id>1</id><amount>10</amount></expense>
<expense> <id>1</id><amount>20</amount></expense>
<expense> <id>1</id><amount>30</amount></expense>
.....
</expenses>
my XSL
<xsl:template match="/">
...
<xsl:for-each select="expenses/expense">
<tr><td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="amount"/></td>
<!-- here is the running total of the amount ????? -->
<xsl:variable name="temp" select="sum(preceding-sibling::expenses/expense/amount) + amount"/>
<td><xsl:value-of select="$temp"/></td>
<tr>
</xsl:for-each>....
and it gives
<tr><td>1</td><td>10</td><td>10</td></tr>
<tr><td>2</td><td>20</td><td>20</td></tr>
<tr><td>2</td><td>20</td><td>30</td></tr> ...
instead of
<tr><td>1</td><td>10</td><td>10</td></tr>
<tr><td>2</td><td>20</td><td>30</td></tr>
<tr><td>2</td><td>20</td><td>60</td></tr>...
What did i do wrong? or how ca i implement something similar to the following VB code in XSL
A= 0
for (i=1 to 10)
a = a + somevalue
' display a
next i
Thank you