xsl-list
[Top] [All Lists]

RE: [xsl] length of string from a set of nodes.

2009-03-27 14:32:38
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/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>