I wish to append the value of a variable to itself each time it iterates through a for-each, problem is I’m not sure on how to go about this. Here is what I currently have:
<xsl:variable name="lineQty" select="0" />
<xsl:for-each select="/*/*/*/*/*/xsales:CustInvoiceTrans">
<xsl:value-of select="$lineQty + (xsales:LineNum * xsales:Qty)" />
</xsl:for-each>
<test>
<xsl:value-of select="$lineQty" />
</test>
This just outputs 0
Edit
I changed it to the following:
<xsl:variable name="lineQty">
<xsl:for-each select="/*/*/*/*/*/xsales:CustInvoiceTrans">
<xsl:value-of select="xsales:LineNum * xsales:Qty" />
</xsl:for-each>
</xsl:variable>
But this outputs 12345. The reason for this is that it’s done 1×1, 2×1, 3×1, 4×1, 5×1 as my 5 lines each have a quantity of 1. So all that needs to happen now is adding up these values, is that possible?
Are you using XSLT 2.0? If so, try this:
EDIT
@Markus suggested even shorter version:
Thanks 🙂