This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: sum (substring-before)
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] sum (substring-before)
- From: "Ben Robb" <b dot robb at cscape dot com>
- Date: Fri, 24 Aug 2001 16:58:56 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
<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@wishstream.com]
> Sent: 24 August 2001 15:31
> To: XSL-List@lists.mulberrytech.com
> 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