[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using sum to Produce a total from combined documen

Subject: Re: Using sum to Produce a total from combined documents
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 4 Jul 2002 12:02:43 +0100
total subtotal sum
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.