[xsl] position() problem

Subject: [xsl] position() problem
From: Graham Seaman <graham@xxxxxxxxx>
Date: Tue, 6 Nov 2001 17:34:04 +0000 (GMT)
Hi all,

I have some input like this:

<a label="level1">a</a>
<a label="level2">b</a>
<a label="level3">c</a>
<a label="level3">d</a>
<a label="level1">e</a>
<a label="level2">f</a>
<a label="level2">g</a>
<a label="level1">h</a>

and I want output like:


The template below half works; in particular, it fails to pick up
when the level of the preceding <a> is one greater than the current level,
which is the cue to output <strong>. I've tried all the variations I can
think of on position() and preceding-sibling, and think there must be
something basic I'm not getting...

If anyone knows what it is, I'd be grateful :-)


xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="html"/>

  <xsl:template match="/">
    <xsl:call-template name="a-nav">
name="the-as" select="//a[contains(@label,'level')]"/>
      <xsl:with-param name="level" select="'5'"/>

  <xsl:template name="a-nav">
    <xsl:param name="the-as"/>
    <xsl:param name="level"/>
      <!-- exit recursion -->
      <xsl:when test="$level = '0'"/>
        <xsl:for-each select="$the-as[contains(@label, $level)]">
	  <!-- get the heading for the next row -->
          <xsl:if test="contains($the-as[position()-1]/@label, $level -
	  <!-- print out the row -->
          <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:template match="a">
    <xsl:value-of select="."/>


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

Current Thread