Re: [xsl] 'interleaved' numbering

Subject: Re: [xsl] 'interleaved' numbering
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Aug 2002 17:20:33 +0100
Andrew Welch wrote:
> Anyway, the problem you have is that <theorem> exist within
> <subSect>, therefore <xsl:number> is no good. Also, counting
> preceding-sibling::theorem's is no good as you want only those that
> are in the current <section>.
>
> So I would recommend creating a variable with the values you need, and
> then referencing that variable when you need the number.  So as a
> top-level-element (child of the root) you would want a variable like:
[snip]

A simpler solution is to use two xsl:number instructions, one counting
theorems at "any" level, from the nearest section. I don't have the
actual example since attachments don't come through to the list, but
with the source:

<doc>
  <section>
    <subSect>
      <theorem>1.1</theorem>
      <theorem>1.2</theorem>
    </subSect>   
    <subSect>
      <theorem>1.3</theorem>
    </subSect>   
  </section>
  <section>
    <subSect>
      <theorem>2.1</theorem>
    </subSect>   
  </section>
</doc>

and the template:

<xsl:template match="theorem">
  <theorem>
    <xsl:number count="section" />.<xsl:number level="any"
                                               from="section" />
    <xsl:text /> (<xsl:value-of select="." />)<xsl:text />
  </theorem>
</xsl:template>

I get:

<theorem>1.1 (1.1)</theorem>
<theorem>1.2 (1.2)</theorem>
<theorem>1.3 (1.3)</theorem>
<theorem>2.1 (2.1)</theorem>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread