RE: [xsl] Is it possible to reference the previous and next elements inside a for-each

Subject: RE: [xsl] Is it possible to reference the previous and next elements inside a for-each
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Mon, 12 Apr 2004 10:17:50 +0200
> -----Original Message-----
> From: Ian Lang [mailto:ianplang@xxxxxxxxx]
>
>
> I am working on a navigation bar for my output HTML.
> When executing a for-each like this:

Hi,

So, in short, the structure looks like:

<xsl:for-each select="x">
  <xsl:sort select="..."/>
  <xsl:apply-templates mode="createContent"
                       select=".">
    <xsl:with-param name="prevEl"
                    select="..."/>
    <xsl:with-param name="nextEl"
                    select="..."/>
  </xsl:apply-templates>
</xsl:for-each>


Remember that if you were to do:

<xsl:apply-templates select="x"
                     mode="createContent">
  <xsl:sort select="..." />
</xsl:apply-templates>

Then in the matching template the requested previous and following x are
available on the preceding and following (-sibling) axes, so there is really
no need to pass these in with parameters (but if you insist, the axes can be
used to determine the value of the parameter in the above structure as
well..)

<xsl:template match="x" mode="createContent">
  <xsl:variable name="prev"
                select="preceding-sibling::x" />
  <xsl:variable name="next"
                select="following-sibling::x" />
  ...
</xsl:template>


Hope this helps!

Cheers,

Andreas

Current Thread