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 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSLT: XPath: Siblings, Lee Goddard | Thread | Re: [xsl] XSLT: XPath: Siblings, Lee Goddard |
Re: [xsl] pruning nodes not in xpat, Jeni Tennison | Date | Re: [xsl] how do you redefine a var, Jeni Tennison |
Month |