[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

position() problem

Subject: position() problem
From: Graham Seaman <graham@xxxxxxxxx>
Date: Tue, 6 Nov 2001 17:34:04 +0000 (GMT)
xsl contains position
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.