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

Re: Add products of two recursive additions

Subject: Re: Add products of two recursive additions
From: Josh Canfield <joshcanfield@xxxxxxxxx>
Date: Tue, 22 Jun 2004 10:06:59 -0700
xsl variable add
If the structure is as you have described, then why not use sum()?

  <xsl:template match="/">
  <sums>
    c/data: <xsl:value-of select="sum(a/b/c/data)"/>
    d/data: <xsl:value-of select="sum(a/b/d/data)"/>
    all : <xsl:value-of select="sum(a/b/c/data | a/b/d/data)"/>
  </sums>
  </xsl:template>

If you do need the recursive addition then change the template to
return un-formated numbers, store them in variables and add them
together. Or, less efficiently, you could just pass all the nodes to
your existing functions like this:


<xsl:template match="/">
  <xsl:variable name="cd">
    <xsl:call-template name="orderlist.sum.edit">
      <xsl:with-param name="set-of-order" select="/a/b/d | /a/b/c"/>
    </xsl:call-template>
  </xsl:variable>
  <cd>
    <xsl:value-of select="$cd"/>
  </cd>
</xsl:template>

Josh

On Tue, 22 Jun 2004 12:16:46 +0100, James Steven
<jsteven@xxxxxxxxxxxxxxxxxxxxx> wrote:
> 
> Hello
> I have two recursive addition functions producing totals which I would like
> to add together.  How can I do this?
> 
> Eg To produce the first total I have used the xsl shown below:
> 
> <xsl:template match="a">
> <xsl:call-template name="orderlist.sum.edit">
> <xsl:with-param name="set-of-order" select="b/c"/>
> </xsl:call-template>
> </xsl:template>
> 
> The call-template above calls the template below to display the total for
> 'data':
> 
> <xsl:template name="orderlist.sum.edit">
> <xsl:param name="set-of-order"/>
> <xsl:variable name="sumorg">
> <xsl:call-template name="orderlist.sum">
> <xsl:with-param name="set-of-order" select="$set-of-order"/>
> </xsl:call-template>
> </xsl:variable>
> <xsl:value-of select='format-number($sumorg, "£###,###,##0.00")'/>
> </xsl:template>
> 
> <xsl:template name="orderlist.sum">
> <xsl:param name="set-of-order"/>
> <xsl:choose>
> <xsl:when test="$set-of-order">
> <xsl:variable name="first">
> <xsl:apply-templates select="$set-of-order[1]/data"/>
> </xsl:variable>
> <xsl:variable name="rest">
> <xsl:call-template name="orderlist.sum">
> <xsl:with-param name="set-of-order" select="$set-of-order[position() !=
> 1]"/>
> </xsl:call-template>
> </xsl:variable>
> <xsl:value-of select="$first + $rest"/>
> </xsl:when>
> <xsl:otherwise>0</xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> 
> The second total is acquired in the same way.  An example of the xml I am
> using is also shown below:
> 
> <a>
> <b>
>  <c>
>    <data>1</data>
>  </c>
>   <c>
>    <data>3</data>
>  </c>
>  <d>
>    <data>1</data>
>  </d>
>  <d>
>   <data>5</data>
>  </d>
>  <d>
>   <data>2</data>
>  </d>
> </b>
> </a>
> 
> The two call-templates above refering to the recursive addition functions
> produce the totals for <data> in <c> as 5 and <d> as 7. How do I obtain 12
> as the total of both?
> 
> Thankyou very much for your help.
> 
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
> 
>

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.