xsl-list
[Top] [All Lists]

Re: preceding-sibling inside for-each appears to fail

2003-02-09 15:35:40
Hi Ted,

Ted Stresen-Reuter wrote:
...

<p>preceding sibling = <xsl:value-of select="preceding-sibling::attribute/@name" /></p>

...

As you can see, following-sibling successfully returns the following sibling, but preceding-sibling always returns the first node rather than the preceding-sibling node.

You need to remember two things here. First, XPath expressions normally return node-sets. Second, node-sets are processed in document order. So your select expression is returning the first member of the set "preceding-sibling::attribute/@name", which is always the first in document order. But if you put a positional predicate in as part of an XPath step then that is applied in the order of the current axis, so try

<p>preceding sibling = <xsl:value-of select="preceding-sibling::attribute[1]/@name" /></p>

Hope this helps -

Francis.


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list