Re: [xsl] XSLT: XPath: Siblings

Subject: Re: [xsl] XSLT: XPath: Siblings
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 28 Feb 2001 09:53:18 +0000
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


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


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:


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


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 Tennison

 XSL-List info and archive:

Current Thread