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(_at_)redlinesoftware(_dot_)co(_dot_)uk> 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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--