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

Re: string-length of all label attributes

Subject: Re: string-length of all label attributes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 8 Jul 2004 11:11:15 +0100
xsl string length
//@label selects a node set

count() expects a node set and returns its size, so

> But count(//@label) works fine.

But if you use (any) function that expects a string and give it a node
set then it will sort the nodes into document order, and take the string
value of the first node as its argument.  (In XSLT2 draft this is an error
as often as not, but XSLT1 rarely generates run time errors)

so you get

> When I apply string-length(//@label) in the root I only get the length
> of the first attribute.

You might want
<xsl:variable name="x">
<xsl:for-each select="//@label">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="string-length($x)"/>

which would work but actually builds the (result tree fragment containing
the)  string consisting of the concatenation of all the labels which
might be expensive in terms of space if you really have lots of them.

An alternative would be a recursive template that walks over the tree
adding up the string length as it finds labels.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.