Subject: RE: [xsl] sum (substring-before) From: "Ben Robb" <b.robb@xxxxxxxxxx> Date: Fri, 24 Aug 2001 16:58:56 +0100 |
<xsl:template match="/"> <xsl:variable name="plus" select="sum(/values/value[substring-before(.,'CR') = ''])"/> <xsl:variable name="minusnodeset"> <xsl:for-each select="/values/value[not(substring-before(.,'CR') = '')]"> <minus><xsl:value-of select="substring-before(.,'CR')"/></minus> </xsl:for-each> </xsl:variable> <xsl:variable name="minus" select="sum(msxsl:node-set($minusnodeset)/minus)"/> TOTAL VALUE = <xsl:value-of select="($plus) - ($minus)"/> </xsl:template> on an XML file like this: <values> <value>20.00</value> <value>10.00CR</value> <value>5.00CR</value> </values> You have to use a vendor specific extension to make a variable behave like a node-set; in this case I'm using MSXML's node-set. Most of the popular parsers have one... There might be a way using named templates which doesn't need an extension, but its Friday afternoon, the air conditioning has broken, and so I'm not going to look any further *grin*. Ben > -----Original Message----- > From: Winnie Leung [mailto:wleung@xxxxxxxxxxxxxx] > Sent: 24 August 2001 15:31 > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] sum (substring-before) > > > dear all, > > is it possible to do a sum and a substring-before together? > my data: > 20.00 > 10.00CR > 5.00CR > > (CR means negative) > > and i want to get a total of all (i.e. 20.00+(-10.00)+(-5.00) = 5) > > thanks in advance, > wing > > > 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] sum (substring-before), Winnie Leung | Thread | RE: [xsl] sum (substring-before), Sullivan, Dan |
RE: [xsl] FW: Toggling radio button, Friedlander, Hal | Date | RE: [xsl] FW: Toggling radio button, Crowers, Steve |
Month |