This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calculating a sum of rounded numbers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]