This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: position() problem


On Tue, 6 Nov 2001, Graham Seaman wrote:

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

<snipped>

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:choose>
      <xsl:when test="$level = '0'"/>
      <xsl:otherwise>
        <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)">
            <strong><xsl:apply-templates
select="$the-as[$pos]"/></strong><p/>
          </xsl:if>
          <xsl:if  test="contains(./@label, $level)">
            <xsl:apply-templates select="."/><![CDATA[&nbsp;.&nbsp;]]>
          </xsl:if>
        </xsl:for-each>
        <p/>
        <xsl:call-template name="a-nav">
          <xsl:with-param
name="the-as" select="$the-as[not(contains(@label,$level))]"/>
          <xsl:with-param name="level" select="$level - '1'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]