[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: Fred Christian <fredc@xxxxxxxxxx>
Date: Fri, 27 Mar 2009 11:14:23 -0700
Re:  length of string from a set of nodes.
This discussion helps much, thanks.

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()


Should it work?
I am using Saxon from the command line. java -jar "C:\saxon\saxon.jar .....

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, ''))"/>


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.

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

-----Original Message-----
From: Fred Christian [mailto:fredc@xxxxxxxxxx] Sent: 27 March 2009 17:46
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: length of string from a set of nodes.


I was able to get this to work, but while reading about it, I see all these little tips and recommendations regarding being efficient and not creating nodes when you only need strings.

In this code my goal was meet of deciding if the length of all the text concatenated together is greater than 30.
<xsl:variable name="strings" as="xs:string"><xsl:value-of select="answers"/></xsl:variable>
<xsl:variable name="slen" as="xs:integer"><xsl:sequence select="string-length($strings)"/></xsl:variable>
<xsl:for-each select="answers">
<xsl:choose>
<xsl:when test="$slen gt 30"> etc...


I tried various combinations of using the <<concat()>> function, <<xsl:sequence>>, and <<xsl:value-of>>. This is what ended up working.

Is there a "better" way to do this?
Thanks

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.