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

hierarchic counting in flat structures

Subject: hierarchic counting in flat structures
From: Norbert Heidbrink <nh@xxxxxxxx>
Date: Fri, 2 Nov 2012 11:16:58 +0100
 hierarchic counting in flat structures
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

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.