HTML numbering

When transforming XML documents into HTML documents, it may not be necessary to use XSLT features at all. The simplest way to number items automatically is to use the OL (Ordered List) and LI (List Item) elements. In this scenario, the stylesheet does not actually number the items but leaves this task to the browser that will interpret the HTML tags. Take the simple example of a list of procedural steps:

<procedure>
  <step>walk to the door</step>
  <step>insert the key in the lock</step>
  <step>turn the key</step>
  <step>turn the handle</step>
  <step>push</step>
</procedure>

The following templates would suffice:

<xsl:template match="procedure">
  <OL><xsl:apply-templates/></OL>
</xsl:template>

<xsl:template match="step">
  <LI><xsl:apply-templates/> ...

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.