Derek Fountain
Usenet Archive
- Joined
- Jul 17, 2001
- Messages
- 90
- Reaction score
- 0
I'm having trouble understanding the use of XSLT variables. I'm trying to add up the values from a set of elements. The code currently looks like this:
<xsl:variable name="orderTotal">
<xsl:value-of select="0" />
</xsl:variable>
<xsl:for-each select="item">
<xsl:variable name="orderTotal">
<xsl:value-of select="$orderTotal + qty*price" />
</xsl:variable>
</xsl:for-each>
<xsl:value-of select="$orderTotal" />
My 'item's each have a quantity and price, and I can print those values from inside the for-each, so I know they're there to be used.
Under Linux, $orderTotal is always given as zero. Under Windows the XSLT processor gives an error inside the loop saying 'orderTotal' cannot be redefined.
How do I update the value of 'orderTotal' inside my loop?
<xsl:variable name="orderTotal">
<xsl:value-of select="0" />
</xsl:variable>
<xsl:for-each select="item">
<xsl:variable name="orderTotal">
<xsl:value-of select="$orderTotal + qty*price" />
</xsl:variable>
</xsl:for-each>
<xsl:value-of select="$orderTotal" />
My 'item's each have a quantity and price, and I can print those values from inside the for-each, so I know they're there to be used.
Under Linux, $orderTotal is always given as zero. Under Windows the XSLT processor gives an error inside the loop saying 'orderTotal' cannot be redefined.
How do I update the value of 'orderTotal' inside my loop?