This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Converting non-numeric characters to numbers


> For example my XML would be as follows:
> <AAA>
>    <BBB>123</BBB>
>    <BBB>456</BBB>
>    <BBB>-</BBB>
>    <BBB>789</BBB>
> </AAA>
>
> <xsl:variable name="TotalSum" select="sum(AAA/BBB[not '-'])">
>
That should be rejected as a syntax error.

Try <xsl:variable name="TotalSum" select="sum(AAA/BBB[not(.='-')])">

or if you want to reject all the non-numeric ones

<xsl:variable name="TotalSum" select="sum(AAA/BBB[number(.)=number(.)])">

(That's weird, it relies on the fact that the only number that isn't equal
to itself is NaN)

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]