[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|