> 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
|