This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Boolean XPath Expression and sum
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Boolean XPath Expression and sum
- From: Francis Norton <francis at redrice dot com>
- Date: Wed, 09 May 2001 18:37:39 +0100
- References: <001301c0d8aa$993410a0$554f3c3e@PCUKMKA>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Michael Kay wrote:
>
> > I need to sum up the all the values of things where their
> > value is not equal
> > to N/A, and am having a bit of trouble.
> > XML might look like
> > <abuncha>
> > <thing>1</thing>
> > <thing>2</thing>
> > <thing>3</thing>
> > <thing>5</thing>
> > <thing>N/A</thing>
> > </abuncha>
>
> sum(//thing[.!='N/A'])
>
Given that sum() just gives up as soon as it hits a non-number, you
might want to consider
sum(//thing[string(number(.)) != 'NaN'])
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list