Re: [xsl] Preceding-sibling in for-each

Subject: Re: [xsl] Preceding-sibling in for-each
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 22 Mar 2003 12:37:33 +0000
Hi Andrew,

> How I can get "preceding-sibling" node in for-each flow:
>
> <xsl:for-each select="//some-node">
>     <xsl:value-of select="*[position()-1]"/>
> </xsl:for-each>
>
> seems not work.

If I interpret you correctly, you can do something like:

  <xsl:variable name="nodes" select="//some-node" />
  <xsl:for-each select="$nodes">
    <xsl:variable name="pos" select="position()" />
    <xsl:value-of select="$nodes[$pos - 1]" />
  </xsl:for-each>

But it's very inefficient and I doubt that it's the best way to
achieve what you want to achieve. If you told us what you're trying to
do (what your source and desired result is) we might be able to show
you a better approach.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread