|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: sum (substring-before)
<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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








