Name

<xsl:counters>

Synopsis

<xsl:counters name= string format= format />

Description

Provides a named counter that appears in the result tree. The counter is formatted according to the string given using the format attribute. It can be initialized using the element <xsl:counter-reset> and incremented using the element <xsl:counter-increment/>. This differs from the <xsl:counter> element in that it maintains a counter for each level of ancestry it encounters. For example:

<xsl:template match="header">
  <fo:block>
    <xsl:counter-increment name="head"/>
    <xsl:counters name="head" format="1.1. "/>
    <xsl:apply-templates/>
  </fo:block>
  <xsl:counter-reset name="head"/>
</xsl:template>

Here, if we have a document as follows:

<header>The Long Road Home</header>
<header>Joyful Reunions</header>

the counter would return the following result: (1, 2). However, if we had nested levels of the <header> element, such as the following:

<header>The Long Road Home
  <header>Starting the Long Road</header>
  <header>Halfway There</header>
</header>
<header>Joyful Reunions
  <header>Starting the Long Road</header>
  <header>Halfway There</header>
</header>

the counter returns the result (1, 1.1, 1.2, 2, 2.1, 2.2) for the <header> elements that it encounters.

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.