This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: XSLT: XPath: Siblings


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]