This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Performing an expression on attributes of a node-set
- To: xsl-list at mulberrytech dot com
- Subject: Re: Performing an expression on attributes of a node-set
- From: Nick Browne <NickBrowne at slipstone dot co dot uk>
- Date: Wed, 27 Sep 2000 20:33:14 +0100
- Organization: Slipstone Ltd
- References: <00eb01c02889$c9a46a40$0401a8c0@redmenace.org>
- Reply-To: xsl-list at mulberrytech dot com
Jim Sproull wrote:
> But I need the sum of each (price*qty). I tried everything I could think
> of, but no luck. Any clues on how to do this?
A solution follows. However, as an alternative, assuming you are in control of
the source document, could you include another attribute which is simply @qty *
@price. You could then use sum( .. ). Sometimes a bit of redundancy is not a
bad thing !
Otherwise :
<xsl:variable name="Items" select="//Item"/>
<xsl:variable name="TotalValue">
<xsl:call-template name="Total">
<xsl:with-param name="Items" select="$Items"/>
<xsl:with-param name="RunningTotal" select="0"/>
</xsl:call-template>
</xsl:variable>
Total = <xsl:value-of select="format-number($TotalValue, '####0.0#')"/>
</xsl:template>
<xsl:template name="Total">
<xsl:param name="Items"/>
<xsl:param name="RunningTotal"/>
<xsl:choose>
<xsl:when test="not($Items)">
<xsl:copy-of select="$RunningTotal"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="CurrentTotal"
select="$RunningTotal + ($Items[1]/@qty * $Items[1]/@price)"/>
<xsl:call-template name="Total">
<xsl:with-param name="Items" select="$Items[position()>1]"/>
<xsl:with-param name="RunningTotal" select="$CurrentTotal"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Regards
Nick Browne
Slipstone Ltd
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list