This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: sum function
- From: "Hesselberth, Jan" <Jan dot Hesselberth at northernrock dot co dot uk>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 16 Nov 2001 15:43:44 -0000
- Subject: RE: [xsl] sum function
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks for the response.
Cheers
jAN
-----Original Message-----
From: Jörg Heinicke [mailto:joerg.heinicke@gmx.de]
Sent: 16 November 2001 17:52
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] sum function
You said already the solution. Numbers may not be written with ',' in XSLT.
If you definitely want the ',', you must wrote a stylesheet with recursive
templates, which removes the ',' while adding this value to temporary sum.
This problem we had a few days ago on the XSLTalk-list. I gave following
solution:
<xsl:template match="amounts">
<xsl:variable name="sum">
<xsl:apply-templates select="amount[1]"/>
</xsl:variable>
<xsl:value-of select="$sum"/>
</xsl:template>
<xsl:template match="amount">
<xsl:param name="sum" select="0"/>
<xsl:apply-templates select="following-sibling::amount[1]">
<xsl:with-param name="sum" select="$sum +
number(substring-after(.,'£'))"/>
</xsl:apply-templates>
<xsl:if test="not(following-sibling::amount[1])">
<xsl:value-of select="$sum + number(substring-after(.,'£'))"/>
</xsl:if>
</xsl:template>
You must only replace the 'amount' by 'Amount' and the
'substring-after(.,'£')' by 'translate(.,',','')'.
Hope this helps,
Joerg
Hesselberth, Jan wrote:
> How do I use the sum function on xml such as:
>
> <Amount>12,345.12</Amount>
> <Amount>132,345.12</Amount>
> <Amount>2,345.12</Amount>
>
> If I use Total Price = <xsl:value-of select="sum(//Amount)"/> I get the
> result NaN. However, if the data does not contain ',' the sum works
> correctly.
> Any help appreciated.
> Regards
> Jan
--
System Development
VIRBUS AG
Fon +49(0)341-979-7435
Fax +49(0)341-979-7409
joerg.heinicke@virbus.de
www.virbus.de
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--------------------------------------------------------------------------
CONFIDENTIALITY
The information contained in this e-mail and any files transmitted with it
is private and confidential. It is intended for the named addressee only.
If you are not the intended addressee you are prohibited from
storing, copying or using the information in any way.
If you received this e-mail due to a transmission error please notify the
sender immediately. No liability is accepted by Northern Rock
for any losses caused by viruses contracted during transit
over the Internet or present in any receiving system.
This e-mail is not intended to create legally binding commitments on
behalf of Northern Rock plc, nor do its contents reflect the corporate
views or policies of Northern Rock plc.
--------------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list