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

Re: sum function

Subject: Re: sum function
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 16 Nov 2001 18:51:53 +0100
xsl sum function nan
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(.,'&#xA3;'))"/>
</xsl:apply-templates>
<xsl:if test="not(following-sibling::amount[1])">
<xsl:value-of select="$sum + number(substring-after(.,'&#xA3;'))"/>
</xsl:if>
</xsl:template>

You must only replace the 'amount' by 'Amount' and the 'substring-after(.,'&#xA3;')' 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@xxxxxxxxx
www.virbus.de


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.