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

RE: sum function

Subject: RE: sum function
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 16 Nov 2001 16:28:17 -0000
sum function in forms
> 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.

As a general principle, it's best to hold data in XML documents in a form
that's optimised for processing rather than for display to humans. Using
schemas will encourage that further. So I would say, first do a
transformation to a document that holds these numbers in their canonical
form (12345.12 etc), which you can achieve using translate(., ',', ''), and
then apply the summation to the result.

Mike Kay


 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.