This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Calculating a sum of rounded numbers
- From: Greg Faron <gfaron at integretechpub dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 09 May 2002 15:45:00 -0600
- Subject: Re: [xsl] Calculating a sum of rounded numbers
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 02:45 PM 5/9/2002, you wrote:
>I tried
><xsl:value-of select="format-number(sum(format-number(//measure),'##')" />
I assume you mean "value" instead of "measure" above. Try this:
<xsl:variable name="mysum">
<xsl:call-template name="sum-rounded-values">
<xsl:with-param name="value" select="//value" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="format-number($mysum)" />
...
<xsl:template name="sum-rounded-values">
<xsl:param name="value" />
<xsl:param name="_sum" select="0" />
<xsl:choose>
<xsl:when test="value">
<xsl:call-template name="sum-rounded-values">
<xsl:with-param name="value" select="$value[position() > 1]" />
<xsl:with-param name="_sum" select="$_sum +
format-number($value[1],
'##')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$_sum" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
You can further enhance it by making the pattern '##' an argument or
using modes instead of call-template. HTH!
Greg Faron
Integre Technical Publishing Co.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list