Numbering paragraphs

If your document design requires the numbering of paragraphs, such as for statutes or rules, you can use the xsl:number element to do that. You need to customize the template that matches para, but you will need to be careful how you do so. The para element is used in many contexts, not just for body text paragraphs. You might not want to number a para in a table or admonition, for example.

To be more selective, you could add a role="statute" attribute (or any value you choose) to those para elements you want to display a number. Then add this template to your customization layer:

<xsl:template match="para[@role = 'statute']">
  <fo:block xsl:use-attribute-sets="normal.para.spacing">
    <xsl:call-template name="anchor"/>
    <xsl:number count="para[@role = 'statute']" level="any"/>
    <xsl:text>. </xsl:text>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

Or you could use an XPath qualifier to select para based on its lineage (its ancestor elements), in which case you do not need to add role attributes to the document. In this example, only para elements that are direct children of a section or chapter element would be numbered.

<xsl:template match="para[parent::section or parent::chapter]">
  <fo:block xsl:use-attribute-sets="normal.para.spacing">
    <xsl:call-template name="anchor"/>
    <xsl:number count="para[parent::section or parent::chapter]" level="any"/>
    <xsl:text>. </xsl:text>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

Note that you need to change both the match attribute on xsl:template and the count attribute on xsl:number to keep them in sync.

In either case, if you want to restart the numbering in each chapter and perhaps prepend the chapter number, you can use the from attribute of xsl:number that indicates the element to start counting from. The following example restarts numbering in each chapter or appendix and adds the chapter or appendix number.

<xsl:template match="para[parent::section or parent::chapter]">
  <fo:block xsl:use-attribute-sets="normal.para.spacing">
    <xsl:call-template name="anchor"/>
    <xsl:if test="ancestor::chapter">
      <xsl:apply-templates select="ancestor::chapter" mode="label.markup"/>
      <xsl:text>.</xsl:text>
    </xsl:if>
    <xsl:number from="chapter" count="para[parent::section or parent::chapter]" level="any"/>
    <xsl:text>. </xsl:text>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

The from="chapter" attributes restarts numbering at the start of each chapter. The label.markup mode generates the number for whatever numbered item is processed, in this case the ancestor chapter of the current para.