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

RE: length of string from a set of nodes.

Subject: RE: length of string from a set of nodes.
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 27 Mar 2009 18:32:06 -0000
RE:  length of string from a set of nodes.
> > And of course, you could combine the two variables:
> >
> > <xsl:variable name="slen" as="xs:integer" 
> > select="string-length(answers)"/>
> >   
> I got an error when I tried that ???
> XPTY0004: A sequence of more than one item is not allowed as 
> the first argument of string-length()

OK, so child::answers selects more than one element. I didn't know that. You
were using <xsl:value-of select="answers"> to concatenate the values of the
elements (plus some separator spaces), which I hadn't appreciated.
> 
> Should it work?
> 
> But when I used a combined version from Martin's suggestion 
> with string-join.
> <xsl:variable name="slen" as="xs:integer" 
> select="string-length(string-join(answers, ''))"/>

If answers is a sequence of elements, then string-join() is the right
solution.
> 
> It works great.
> 
> Interestingly, when I put a copy of your example in, but with 
> an unused @name. I don't get an error.  I guess it only hits 
> the error when the variable is evaluated.
> 
Yes, Saxon doesn't evaluate variables if they aren't used.

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

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.