Advanced formatting options

The Format attribute provides a very flexible approach to formatting numbers. First, it is possible to make all numbers the same width by padding shorter numbers with leading zeros. This attribute contains the number of digits to be presented, with the zero digit used for all but the last, which must be a one (as in '0001'):

<xsl:template match="item">
  <P>
    <xsl:number format="01"/>. <apply-templates/>
  </P>
</xsl:template>
   <P>01. first item</P>
   <P>02. second item</P>
   <P>03. third item</P>
   ...
   <P>09. ninth item</P>
   <P>10. tenth item</P>

Punctuation is often used within values to create groups of digits for legibility. But the actual mark used and the number of digits in each group may vary. Two attributes are available ...

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.