Table of Contents
More Resources
Numbering Chapters and Sections

Number your chapter and section titles in both the Table of Contents and in the body of the document.
You want to edit a template in the custom-xsl.xsl file ( located in cfg/fo/xsl/) to number chapters and section titles in both the Table of Contents and in the body of the document.
  1. To add prefixes to the titles, modify the mode="get-title” template. Copy and paste the following code into the custom-xsl.xsl:

    Step Information
    < xsl:template match="*" mode="getTitle"> 
      < xsl:variable name="topic" select="ancestor-or-self::*[contains(@class, ' topic/topic ')][1]" /> 
      < xsl:variable name="id" select="$topic/@id" /> 
      < xsl:variable name="mapTopics" select="key('map-id', $id)" /> 
      < fo:inline> 
        < xsl:apply-templates select="$mapTopics[1]" mode="topicTitleNumber"/> 
      < /fo:inline> 
      < xsl:text>  < /xsl:text> 
      < xsl:apply-templates /> 
    < /xsl:template> 
    Note:This template calls the mode="topicTitleNumber" templates, adds a space, and then applies all templates.

  2. In order for the correct numbers to show up, you need to define the topicTitleNumber templates:

    Step Information
    < xsl:template match="*[contains(@class, ' bookmap/chapter ')] |
    	*[contains(@class, ' map/topicref ')]
    	[not(ancestor-or-self::*[contains(@class,' bookmap/frontmatter ')])]"
    	mode="topicTitleNumber"> 
      < xsl:number format="1. " 
    	  count="*[contains(@class, ' map/topicref ')]
    	  [not(ancestor-or-self::*[contains(@class,' bookmap/frontmatter ')])]
    	  | *[contains(@class, ' bookmap/chapter ')]" level="multiple"/> 
    < /xsl:template> 
    This template matches any bookmap chapter or any topicref that’s not in the frontmatter and assigns the topicTitleNumber to be a count of all chapters or topicrefs (not in the frontmatter) counting multiple levels of the format 1.2.3.

  3. Because the default pdf2 plugin allows for separate configuration of numbers in front of the Table of Contents and those in front of the body titles, you need to empty the mode="tocPrefix" templates:

    Step Information
    < xsl:template match="*[contains(@class, ' bookmap/chapter ')] |
    	*[contains(@class, ' bookmap/bookmap ')]/opentopic:map/
    	*[contains(@class, ' map/topicref ')]" mode="tocPrefix"> 
    < /xsl:template> 

    1. Because this template uses the “opentopic” prefix to define the map, we need to add the namespace declaration to the root stylesheet element.

      Step Information
      Add the following attribute to the < xsl:stylesheet> element at the top of the document:

      xmlns:opentopic="http://www.idiominc.com/opentopic"
      Expected Result
      Your root < xsl:stylesheet> element should look like this:

      < xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      	xmlns:fo="http://www.w3.org/1999/XSL/Format" 
      	xmlns:opentopic="http://www.idiominc.com/opentopic"
      	version="2.0"> 
Your chapters and sections are numbered in the Table of Contents and body of the document when publishing to PDF.
Here is an image of the Table of Contents with the numbered prefixes:
And here is an image of the content titles with numbered prefixes: