|
Subject: Add products of two recursive additions From: "James Steven" <JSteven@xxxxxxxxxxxxxxxxxxxxx> Date: Tue, 22 Jun 2004 12:16:46 +0100 |
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.
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Remapping image paths, Josh Canfield | Thread | Re: [xsl] Add products of two recur, Josh Canfield |
| RE: [xsl] Output character referenc, Andrew Welch | Date | RE: [xsl] EXCEPTION: javax.xml.tra, Michael Kay |
| Month |