Re: [xsl] position() problem

Subject: Re: [xsl] position() problem
From: Graham Seaman <graham@xxxxxxxxx>
Date: Wed, 7 Nov 2001 19:12:23 +0000 (GMT)
On Tue, 6 Nov 2001, Graham Seaman wrote:

> Hi all,
> I have some input like this:


And I posted a completely messed up template to go along with it
(it had been hacked around too many times). Here's a working version,
which gets round the position() problem by storing the position as a
variable at a point where the context is the correct one. But I've just
seen Jeni post that the correct answer is to use preceding::sibling,
so I guess I'll have another go at writing it using that...

  <xsl:template name="a-nav">
    <xsl:param name="the-as"/>
    <xsl:param name="level"/>
      <xsl:when test="$level = '0'"/>
        <xsl:for-each select="$the-as">
        <xsl:variable name="pos" select="position() - 1"/>
          <xsl:if test="contains(./@label, $level) and
contains($the-as[$pos]/@label, $level - 1)">
          <xsl:if  test="contains(./@label, $level)">
            <xsl:apply-templates select="."/><![CDATA[&nbsp;.&nbsp;]]>
        <xsl:call-template name="a-nav">
name="the-as" select="$the-as[not(contains(@label,$level))]"/>
          <xsl:with-param name="level" select="$level - '1'"/>

 XSL-List info and archive:

Current Thread