This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using sum to Produce a total from combined documents
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Eric Vitiello Jr." <xsl-list at perceive dot net>
- Cc: xsl-list <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 4 Jul 2002 12:02:43 +0100
- Subject: Re: [xsl] Using sum to Produce a total from combined documents
- Organization: Jeni Tennison Consulting Ltd
- References: <02Jul2.140816edt.119168@pcbhi266.bhsi.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Eric,
> I need to get a total using a calculation.
Then you need a recursive template that steps through the nodes for
which you want to calculate a subtotal, keeping track of the total as
it goes:
<xsl:template name="total">
<xsl:param name="quotes" select="equity-quote" />
<xsl:param name="total" select="0" />
<xsl:choose>
<xsl:when test="$quotes">
<xsl:variable name="quote" select="$quotes[1]" />
<xsl:variable name="subtotal"
select="$config/stocks/stock[@symbol=$quote/@symbol]/@shares *
$quote/last-sale-price" />
<xsl:call-template name="total">
<xsl:with-param name="quotes"
select="$quotes[position() > 1]" />
<xsl:with-param name="total"
select="$total + $subtotal" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$total" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
To insert the total, just call the template:
<xsl:call-template name="total" />
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list