Hi,
I use this call when I have matched="saledetails":
<xsl:call-template name="grandtotal">
<xsl:with-param name="nodenumber" select="1"/>
<xsl:with-param name="grandtotal" select="0"/>
</xsl:call-template>
To this template:
<xsl:template name="grandtotal">
<xsl:param name="nodenumber"/>
<xsl:param name="grandtotal"/>
<xsl:choose>
<xsl:when test="not(item[$nodenumber])">
<xsl:value-of select="format-number($grandtotal, '#0.00')"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="grandtotal">
<xsl:with-param name="nodenumber" select="$nodenumber+1"/>
<xsl:with-param name="grandtotal"
select="$grandtotal+(item[$nodenumber]/units *
item[$nodenumber]/unit.price)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This works but I'm just wondering is there a simpler method
for doing this?
Not really. You could use e.g. FXSL so you wouldn't have to write the recursive
template; implementation-wise, I'd probably use e.g.
<xsl:apply-templates select="item[1]" mode="sum"/>
in saledetails element with
<xsl:template match="item" mode="sum">
<xsl:param name="grandtotal" select="0" />
<xsl:choose>
<xsl:when test="not(following-sibling::item)">
<xsl:value-of select="format-number($grandtotal+(units * unit.price),
'#0.00')"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="following-sibling::item[1]" mode="sum">
<xsl:with-param name="grandtotal" select="$grandtotal+(units *
unit.price)"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
but that's just a matter of taste and doesn't make the template any more
simple, really.
Cheers,
Jarno
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list