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

Subject: RE: [xsl] length of string from a set of nodes.
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 27 Mar 2009 18:32:06 -0000
> > 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
> 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

Current Thread