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

Re: counting again

Subject: Re: counting again
From: Christoph.Oberle@xxxxxxxxxx
Date: Fri, 13 Jul 2001 18:55:59 +0200
christoph oberle
Hallo Michael,

for numbering you should use <xsl:number>:

If you just use this
      <xsl:number level="any" count="*[name() = $name]"/>
instead of
      <xsl:value-of select="count(preceding-sibling::*[name()=$name])" />
in your code, it will count all preceding nodes of name = $name at any level in
the document tree.

The counting at the end can be done with count():
      <xsl:value-of select="count(//EL1)"/>

The modified stylesheet looks like this:

<xsl:template match="/">
  <xsl:apply-templates/>
  <xsl:call-template name="countings"/>
</xsl:template>

<xsl:template match="EL1 | EL2">
  <xsl:variable name="name" select="name()"/>
  <xsl:copy>
    <xsl:element name="{$name}_NR">
      <xsl:number level="any" count="*[name() = $name]"/>
      <!-- instead of: xsl:value-of
select="count(preceding-sibling::*[name()=$name])" / -->
    </xsl:element>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template name="countings">
  <COUNTINGS>
    <EL1_LNR><xsl:value-of select="count(//EL1)"/></EL1_LNR>
    <EL2_LNR><xsl:value-of select="count(//EL2)"/></EL2_LNR>
  </COUNTINGS>
</xsl:template>

Caution: Numbering is starting with 1 not with 0!

Greetings | Grüße  ;-)
Christoph



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


Current Thread
  • counting again
    • Michael Schäfer - Thu, 12 Jul 2001 08:34:13 -0400 (EDT)
      • <Possible follow-ups>
      • Christoph . Oberle - Fri, 13 Jul 2001 13:01:01 -0400 (EDT) <=

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.