Subject: RE: [xsl] Calculating a sum of rounded numbers From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Thu, 9 May 2002 23:28:46 +0100 |
It's the old problem of getting the sum of a computed expression. Solutions include: - creating a temporary tree containing the computed values, then doing sum() on the nodes in the temporary tree - writing a recursive template to do the summation - using the saxon:sum() extension function - using Dimitre's FXSL library - using XSLT 2.0 / XPath 2.0 Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Nik Krimm > Sent: 09 May 2002 21:45 > To: xsl-mulberry > Subject: [xsl] Calculating a sum of rounded numbers > > > I am trying the following output from the XML below: > > [output] > .21 > .09 > .2 > sum: .5 > > [xml] > <values> > <value>.2123</value> > <value>.0923</value> > <value>.2012</value> > </values> > > [xsl] > <xsl:for-each select="value"> > <xsl:value-of select="format-number((.),'.##')" /><br /> > </xsl:for-each> > sum: <xsl:value-of select="format-number(sum(//value),'.##)" /> > > Instead I'm getting the output > > [output] > .21 > .09 > .2 > sum: .51 > > i.e. a rounding error because the numbers are sumed first and > then rounded, rather than rounded first and then summed. > > > I tried > <xsl:value-of > select="format-number(sum(format-number(//measure),'##')" /> > > But get an error: > Argument 1 must return a node-set. > format-number(-->sum(format-number(//measure),'##')<--) > > Can anyone suggest a better way to approach this problem that > is native xsl (i/e/ without extensions)? > > > TIA > > nik > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Calculating a sum of rounded , Nik Krimm | Thread | Re: [xsl] Calculating a sum of roun, Greg Faron |
RE: [xsl] CDATA block to node set., Michael Kay | Date | Re: [xsl] Strange Parameter Behavio, David Carlisle |
Month |