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

Re: XSLT: XPath: Siblings

Subject: Re: XSLT: XPath: Siblings
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Wed, 28 Feb 2001 10:34:54 +0000
xsl xpath sibling

Lee Goddard wrote:
> 
> My understanding of this has to be wrong:
> 
It is :)

> <xsl:apply-templates/>
> 
> <xsl:template match="/*/*">
>          | <xsl:value-of select="name()"/>
>          ---
>          <xsl:value-of select="preceding-sibling::*[name()]"/> |
> </xsl:template>
> 
> Shouldn't the second clause above output the value
> of the name of the preceding sibling?  It seems to be
> outputting the text content of the first element on
> the page.  I can't understand why?
> 
Because the stuff inside the square bracket is a predicate, like an SQL
where clause. That's why you're getting content rather than name. 

The reason you're getting the first one is, I suspect, that although the
preceding-sibling axis is ordered <em>as far as predicates on it are
concerned</em>. Once you've applied an accidental predicate which
selects every element on the axis (because every element has a name,
which got converted to a boolean true) the result of the expression is a
good old-fashioned un-ordered node-set. xsl:value-of converts its select
argument to a string as if by string(), and the XPath spec says: 

"The string function converts an object to a string as follows:

              A node-set is converted to a string by returning the
string-value of the node in the node-set that is first in document
order. If the node-set is empty, an empty string is returned."

In other words, you want something like 

	<xsl:value-of select="name(preceding-sibling::*[1])"/>

> All I ever do is ask questions here... many thanks for
> all the help I get; I can repay you on the Perl lists
> at activestate.com....
> 
No problem :)

Francis.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.