I need to multiply each of two nodes and find total sum, like quantity * perUnit
and find total of all Products.
How could it be done?
<Products>
<Product>
<name>TestProduct</name>
<quantity>3</quantity>
<perUnit>14.88</perUnit>
</Product>
<Product>
<name>Another Product</name>
<quantity>1</quantity>
<perUnit>2.45</perUnit>
</Product>
<Product>
<name>One more product</name>
<quantity>2</quantity>
<perUnit>4.71</perUnit>
</Product>
</Products>
I tried to do it like this:
<xsl:variable name="TotalPrice">
<xsl:for-each select="./Products/Product">
<xsl:value-of select="quantity * perUnit"/>
</xsl:for-each>
</xsl:variable>
And then
<xsl:value-of select="sum($TotalPrice)"/>
Also tried this:
<xsl:value-of select="sum(//quantity * //perUnit)"/>
But got an error:
Can not convert #NUMBER to a NodeList!