mjs80
12-08-2009, 06:51 PM
Hi I am fairly new to XML/XSL and have tried searching around for what I am looking for with no success. Basically I have created a variable that is creating a sub total for each product on an invoice (this works). I then need to calculate and output the overall total price, this needs to be output outside of the for-each...but if I do this I get an undefined variable error. I understand the for-each is a child node meaning that the $subtotal variable is not global. could you point me in the right direction here. thanks
<xsl:for-each select="DeliveryDetails/ProductOrder">
<tr align="center">
<td width="150"><xsl:value-of select="Description" /></td>
<td width="150"><xsl:value-of select="ReferenceNo" /></td>
<td width="100"><xsl:value-of select="Quantity" /></td>
<td width="100">£<xsl:value-of select="Price" /></td>
<td width="100">£ <xsl:variable name="subtotal" select="Quantity*Price" /><xsl:value-of select="$subtotal" /></td>
</tr>
</xsl:for-each>
<xsl:value-of select="count($subtotal)"/>
<xsl:for-each select="DeliveryDetails/ProductOrder">
<tr align="center">
<td width="150"><xsl:value-of select="Description" /></td>
<td width="150"><xsl:value-of select="ReferenceNo" /></td>
<td width="100"><xsl:value-of select="Quantity" /></td>
<td width="100">£<xsl:value-of select="Price" /></td>
<td width="100">£ <xsl:variable name="subtotal" select="Quantity*Price" /><xsl:value-of select="$subtotal" /></td>
</tr>
</xsl:for-each>
<xsl:value-of select="count($subtotal)"/>