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

RE: get the sum of a sequence of numbers

Subject: RE: get the sum of a sequence of numbers
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 26 Apr 2006 22:05:40 +0100
sum of sequence
> That does not seem to work in this situation.

Gives the wrong answer? Gives an error message? Catches fire? It's a lot
easier to diagnose problems when you know what the symptoms are.

> 
>         <xsl:variable name="mbt" select="sum(for $n in 
> number($mb) return number($n))"/>

number($mb) is going to produce a single number as its result. So this is
the same as select="sum(number($mb))" which is the same as
select="number($mb)". I don't know what $mb is, but if it's a sequence of
strings that can be converted to numbers then you want

>         <xsl:variable name="mbt" select="sum(for $n in $mb return
number($n))"/>

that is, you want to convert the strings to numbers individually.

However, $mb isn't a sequence of strings, because you declared it as:

      <xsl:variable name="mb">
           <xsl:apply-templates mode="mb"/>
       </xsl:variable>  

which means $mb is actually a single document node; so the "for" expression
isn't going to do anything useful. I can't tell how to correct this without
knowing what's coming back from the apply-templates.

> Do I need to define the data type of the sequence? 

It never does any harm, and it sometimes means you get better diagnostics
(or error messages rather than empty output).

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.