Re: [xsl] counting again

Subject: Re: [xsl] counting again
From: Christoph.Oberle@xxxxxxxxxx
Date: Fri, 13 Jul 2001 18:55:59 +0200
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:call-template name="countings"/>

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

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

Caution: Numbering is starting with 1 not with 0!

Greetings | Grüße  ;-)

 XSL-List info and archive:

Current Thread