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 <xsl:counter-reset>
element and incremented using the <xsl:counter-increment/> element.
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:
<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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access