Name

<xsl:counter>

Synopsis

<xsl:counter name= string />

Description

Provides a named counter that appears in the result tree. The counter is initialized using the <xsl:counter-reset/> element and incremented using the <xsl:counter-increment/> element. Consider the following XML document:

<book>
  <chapter>Introduction</chapter>
  <chapter>Learning to Fly</chapter>
  <chapter>Simple Aerobatics</chapter>
</book>

The following XSL numbers and lists each of the chapters in the result tree:

<xsl:template match="book">
  <xsl:counter-reset name="chaps"/>
  <xsl:apply-templates>
</xsl:template>
<xsl:template match="book/chapter">
  <xsl:text>Chapter </xsl:text>
  <xsl:counter name="chaps"/>
  <xsl:counter-increment name="chaps"/>
  <xsl:text>:</xsl:text>
  <xsl:apply-templates>
</xsl:template>

Get XML Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.