I. An XSLT solution -- no extension functions required:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="QuantityTotal">
<xsl:copy>
<xsl:call-template name="sumProducts">
<xsl:with-param name="pNodes" select="../Items/Item"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="sumProducts">
<xsl:param name="pNodes"/>
<xsl:param name="pSum" select="0"/>
<xsl:param name="pEname1" select="'Price'"/>
<xsl:param name="pEname2" select="'Quantity'"/>
<xsl:choose>
<xsl:when test="not($pNodes)">
<xsl:value-of select="$pSum"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="sumProducts">
<xsl:with-param name="pNodes" select=
"$pNodes[position() > 1]"/>
<xsl:with-param name="pSum" select=
"$pSum
+
$pNodes[1]/*[name()=$pEname1]
*
$pNodes[1]/*[name()=$pEname2]
"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on the provided XML document:
<PO>
<Items>
<Item>
<Price>2</Price>
<Quantity>5</Quantity>
</Item>
<Item>
<Price>3</Price>
<Quantity>2</Quantity>
</Item>
</Items>
<QuantityTotal></QuantityTotal>
</PO>
the wanted result is produced:
<PO>
<Items>
<Item>
<Price>2</Price>
<Quantity>5</Quantity>
</Item>
<Item>
<Price>3</Price>
<Quantity>2</Quantity>
</Item>
</Items>
<QuantityTotal>16</QuantityTotal>
</PO>
II. An XSLT 2.0 solution:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="QuantityTotal">
<xsl:copy>
<xsl:sequence select="sum(/*/Items/Item/(Price*Quantity))"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on the same XML document, the wanted, correct result is produced:
<PO>
<Items>
<Item>
<Price>2</Price>
<Quantity>5</Quantity>
</Item>
<Item>
<Price>3</Price>
<Quantity>2</Quantity>
</Item>
</Items>
<QuantityTotal>16</QuantityTotal>
</PO>