[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] hierarchic counting in flat structures


Subject: Re: [xsl] hierarchic counting in flat structures
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Fri, 02 Nov 2012 10:48:57 +0000

Have you tried

<xsl:number from="H3"/>

Michael Kay
Saxonica

On 02/11/2012 10:16, Norbert Heidbrink wrote:
Hi everyone,

given a structure like

<H3>b&</H3>
   <H4>b&</H4>
   <H4>b&</H4>

<H3>b&</H3>
   <H4>b&</H4>

<H3>b&</H3>
   <H4>b&</H4>
   <H4>b&</H4>
   <H4>b&</H4>


I would like to number the H4, re-starting on every H3. So the output is something like this:

H3: 1
   H4: 1
   H4: 2
H3: 2
   H4: 1
H3: 3
   H4: 1
   H4: 2
   H4: 3

The following xsl does the job, but I wonder if this solution is really
effective and elegant.

<xsl:template match="H4">
   <xsl:text>&#x0a;  H4: </xsl:text>
   <xsl:variable name="myH3" select="preceding-sibling::H3[1]" />
   <xsl:value-of select="1 + count(preceding-sibling::H4[preceding-
sibling::H3 = $myH3])" />
</xsl:template>

Are there better ways to solve my problem?

Best regards and thanks for brainstorming,
Norbert


Current Thread
Keywords
xsl