Elements to count

Previous examples have implicitly counted occurrences of the current element, using the sibling elements as context. However, it is possible to override this simple behaviour in various ways: only counting the element under certain conditions, adding other elements into the count, or separately counting other elements.

Selective counting

The Count attribute is used in the Number element to control counting. When this attribute is given a value that matches the current element name, this is equivalent to not including the attribute at all. The two examples below are therefore equivalent:

<xsl:template match="item">
  <P><xsl:number/>...</P>
</xsl:template>

<xsl:template match="item">
  <P><xsl:number count="item"/>...</P> </xsl:template> ...

Get XSL companion, The 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.