not resetting counters in a document tree

Subject: not resetting counters in a document tree
From: Michel Goossens <Michel.Goossens@xxxxxxx>
Date: Mon, 26 Apr 1999 17:10:53 +0200 (METDST)
Using the previous version of the XSL standard I could organize my
counters so that some were numbered automatically using the built-in
procedures using <xsl:number>, that number nodes in the result tree
and others were under my own control using <xsl:counter> and
<xsl:counter-increment>. However, counters have disappeared from the new
spec, so that I can only (as far as I can see) rely on numbering nodes in
the result tree starting at a given parent node. However, consider the
following situation (which occurs quite often in books), where I have
different parts and chapters, but the chapters are numbered sequentially
independently of the parts where they occur, e.g. 

Part I
Chapter 1
Chapter 2
Chapter 3
Part II
Chapter 4
Chapter 5
etc.

I looked in vain for a way to achieve this using the following XML file

<?xml version="1.0" encoding='ISO-8859-1'?> 
<document>
<part>
<stitle>Part I</stitle>
<chapter id="Ch1">
<stitle>First chapter</stitle>
</chapter>
<chapter id="Ch2">
<stitle>Second chapter</stitle>
</chapter>
<chapter id="Ch3">
<stitle>Third chapter</stitle>
</chapter>
</part>
<part>
<stitle>Part II</stitle>
<chapter id="Ch4">
<stitle>Fourth chapter</stitle>
</chapter>
<chapter id="Ch5">
<stitle>Fifth chapter</stitle>
</chapter>
<chapter id="Ch6">
<stitle>Sixth chapter</stitle>
</chapter>
</part>
</document>

And XSL stylesheet

<?xml version='1.0'?>
<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
	xmlns="http://www.w3.org/TR/REC-html40";
        result-ns="">

<xsl:template match="part|chapter">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match="chapter/stitle">
  <xsl:element name="H1">
  <A NAME="{../@id}">
  <xsl:number level="multi" 
              count="chapter"
              format="1. "/>
  <xsl:apply-templates/>
  </A>
  </xsl:element>
</xsl:template>
</xsl:stylesheet>

But, as expected, in the generated output below, the chapter counters are
reset when the new part starts.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Part I

<H1><A NAME="Ch1">1. First chapter</A></H1>

<H1><A NAME="Ch2">2. Second chapter</A></H1>

<H1><A NAME="Ch3">3. Third chapter</A></H1>

Part II

<H1><A NAME="Ch4">1. Fourth chapter</A></H1>

<H1><A NAME="Ch5">2. Fifth chapter</A></H1>

<H1><A NAME="Ch6">3. Sixth chapter</A></H1>

Is there a way of rewriting the style sheet so that this does not happen?

----------------------------------------------------
Dr. Michel Goossens         Phone: (+41 22) 767-5028
IT Division                 Fax:   (+41 22) 767-8630
CERN                        Email:  goossens@xxxxxxx
CH-1211 Geneva 23    F-01631 CERN Cedex
Switzerland          France




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


Current Thread