[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: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 28 Feb 2001 09:53:18 +0000
xpath sibling
Hi Lee,

> <xsl:value-of select="preceding-sibling::*[name()]"/> |
>
> 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?

The path there selects *all* the elements that are preceding siblings
of the current node that have a name.  Since they all have a name, it
selects all the preceding sibling elements.  When you do xsl:value-of
on a node set, you get the string value of the *first* node in the
node set, the one that's first in the document tree, so you always get
(in your situation) the name of the first node in the document tree.

So, several things.  First, getting the name of a node involves the
syntax:

  name(node)

i.e. the node that you want the name of is the argument to the
function.  That gives you:

  name(preceding-sibling::*)

This will give you the name of the first preceding sibling element in
document order.  If you want the name of the immediately preceding
sibling element, then you want:

  name(preceding-sibling::*[1])

The [1] there gives the first element *in reverse document order*
because the preceding-sibling axis is a backwards axis.  An
alternative is:

  name((preceding-sibling::*)[last()])

That collects all the preceding sibling elements together before
getting the last of them (i.e. the one lowest down, closest to the
context node).
  
I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.