[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: sum (substring-before)

Subject: RE: sum (substring-before)
From: "Ben Robb" <b.robb@xxxxxxxxxx>
Date: Fri, 24 Aug 2001 16:58:56 +0100
xsl sum minus
<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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.