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]

position() problem


Hi all,

I have some input like this:

<document>
<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>
</document>

and I want output like:

<strong>b</strong><p/>
c.d<p/>
<strong>a</strong>
b<p/>
<strong>e</strong><p/>
f.g<p/>
a.e.h<p/>

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 :-)

Graham
-----------------------------------------------------------

<xsl:stylesheet
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">
      <xsl:with-param
name="the-as" select="//a[contains(@label,'level')]"/>
      <xsl:with-param name="level" select="'5'"/>
    </xsl:call-template>
  </xsl:template>


  <xsl:template name="a-nav">
    <xsl:param name="the-as"/>
    <xsl:param name="level"/>
    <xsl:choose>
      <!-- exit recursion -->
      <xsl:when test="$level = '0'"/>
      <xsl:otherwise>
        <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 -
'1')">
            <strong><xsl:apply-templates
select="$the-as[position()-1]"/></strong><p/> 
          </xsl:if>
	  <!-- print out the row -->
          <xsl:apply-templates select="."/><![CDATA[&nbsp;.&nbsp;]]>
        </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:template match="a">
    <xsl:value-of select="."/>
  </xsl:template>

</xsl:stylesheet>



 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]