xsl:number (3 )

  1. number_3-input.xml

  2. <?xml version="1.0"?>
  3. <document>
  4.   <h1>Alpha</h1>
  5.   <section>
  6.     <h2>Golf</h2>
  7.     <subsection>
  8.       <h3>Charlie</h3>
  9.     </subsection>
  10.     <subsection>
  11.       <h3>India</h3>
  12.     </subsection>
  13.   </section>
  14. </document>
  1. number_3-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.   <xsl:output indent="yes"/>
  5.   <xsl:template match="@*|node()">
  6.     <xsl:copy>
  7.       <xsl:apply-templates select="@*|node()"/>
  8.     </xsl:copy>
  9.   </xsl:template>
  10.   <xsl:template match="h2">
  11.     <xsl:copy>
  12.       <xsl:number count="section" level="multiple" format="1. " />
  13.       <xsl:apply-templates select="@*|node()"/>
  14.     </xsl:copy>
  15.   </xsl:template>  
  16.   <xsl:template match="h3">
  17.     <xsl:copy>
  18.       <xsl:number count="section|subsection" level="multiple" format="1.1 " />
  19.       <xsl:apply-templates select="@*|node()"/>
  20.     </xsl:copy>
  21.   </xsl:template>
  22. </xsl:stylesheet>
  1. number_3-output.xml

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <document>
  4.   <h1>Alpha</h1>
  5.   <section>
  6.     <h2>1. Golf</h2>
  7.     <subsection>
  8.       <h3>1.1 Charlie</h3>
  9.     </subsection>
  10.     <subsection>
  11.       <h3>1.2 India</h3>
  12.     </subsection>
  13.   </section>
  14. </document>

Comment

xsl:number has very many attributes for fine tuning. See: http://www.w3.org/TR/xslt20/#number  .

Updated 2009-03-19