Difficulty: ★☆☆ (easy)
Keywords: numbering, figures

Problem

You want to enumerate your figures, tables, program listings, or examples consistently throughout your document.

Solution

Use a customization layer and insert the following template into your customization layer:

Example 2.4. Template to Number Figures Consistently
<xsl:template match="d:figure" mode="label.markup"> 1
    <xsl:choose>
      <xsl:when test="@label"> 2
        <xsl:value-of select="@label"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:number format="1" from="d:book|d:article" level="any"/> 3
      </xsl:otherwise>
    </xsl:choose>
</xsl:template>

1

Matches figure elements in label.markup mode (a special mode for getting or calculating numbers).

2

If the figure contains a label attribute, it will be used. This gives you the possibility to overwrite the displayed label.

3

Calculates the number of the current figure element, starting on a book or article level.

Discussion

The template shown in Example 2.4 matches only figures. It can be extended to match also procedures, tables, examples etc. If you do not need the support for the label attribute, remove the xsl:choose and its children, but leave the xsl:number element.

If you need a different numbering schema, modify the format attribute in the xsl:number start-tag. For example, if you write [a] you will get consecutive lowercase letters in brackets like [a], [b], [c] etc.


Project@GitHubIssue#7