Table of Contents
More Resources
Numbering Chapters and Tables
Numbering
Customize your PDF by numbering elements in the Table of Contents and body content.
Numbering Chapters and Sections
Number your chapter and section titles in both the Table of Contents and in the body of the document.
Numbering Tables
By default table numbering is generated based on the table's position in the map. You can configure your PDF output to generate table numbering based on the title number and position in a topic.
Numbering

Customize your PDF by numbering elements in the Table of Contents and body content.
You can add chapter, section, and table numbering to your PDF output. For chapters and sections, the numbering appears in both the Table of Contents and body content. It is generated using the map hierarchy, so each new map level creates a new level in the numbering. Table numbering is generated using the topic title and position within the topic.
To add chapter and section numbering, use the procedure in Numbering Chapters and Sections.
To add table numbering, use the procedure in Numbering Tables.

Map Structure for Chapter and Section Numbering

Chapter and section numbering is generated based on the map structure. To create multi-level title numbering, you must nest topics within a map. For example:
  • Map
    • Installing
      • Installing hard drives or other storage
        • Remove the cover of your system
        • Attach the drive to your system
        • Replace the cover of your system
      • Installing your own Web Server
        • Close all your programs
        • Run Setup.exe
        • Restart your system
      • Installing your own Database
    • Configuring
      • Configuring hard storage devices
      • Configuring your Web Server
      • Configuring a Database
Based on the map structure above, here’s an example of your Table of Contents:
And here’s an example of your content pages:

Map Structure for Table Numbering

Table numbering is generated based on the topic title and the table’s position in the topic. So you can insert tables and table titles normally in a topic, and it’ll generate the following multi-level numbering based on the map structure used for numbering chapters and sections:
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:

Numbering Tables

By default table numbering is generated based on the table’s position in the map. You can configure your PDF output to generate table numbering based on the title number and position in a topic.
To configure the table numbering to generate based on the title number, you must first use the procedure in Numbering Chapters and Sections to insert title numbers.
You want to edit a template in the custom-xsl.xsl file (located in cfg/fo/xsl/) to number tables based on its position in the topic and the title number.
  1. The default table title template gets the variable for “Table” (that’s defined in the cfg/common/vars/en.xsl file) based on the position in the map. The table numbering does not restart at the beginning of each new title.

    Step Information
    This is the structure of the Table variable. You won’t need to modify this, you can simply pass in a different value to the “number” parameter.

    < variable id="Table"> Table < param ref-name="number"/> : < param ref-name="title"/> < /variable> 
    Step Information
    This is the default table title template. Copy and paste this into your custom-xsl.xsl file within your plugin so that you can modify it.

    < xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]">    < fo:block xsl:use-attribute-sets="table.title">      < xsl:call-template name="commonattributes"/>      < xsl:call-template name="insertVariable">        < xsl:with-param name="theVariableID" select="'Table'"/>        < xsl:with-param name="theParameters">          < number>            < xsl:number level="any" count="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" from="/"/>          < /number>          < title>            < xsl:apply-templates/>          < /title>        < /xsl:with-param>      < /xsl:call-template>    < /fo:block>  < /xsl:template> 
  2. You can now modify the < number> parameter to be whatever you want. For this example, you can change it to display the nested number that reflects the topic that the table is contained within, as well as the number of that title within that topic. 

    Example
    If you structure your map like this:

    - root.ditamap 	- topic1.dita (contains two tables) 	- topic2.dita 		- topic3.dita (contains two tables)
    And configure your plugin using this guide, your table numbering will display when published to PDF output as:

    1. Topic1 	Table 1.1: Table title 	Table 1.2: Table title 2. Topic2 	2.1 Topic3 		Table 2.1.1: Table title 		Table 2.1.2: Table title
  3. To calculate the table number, recalculate the topic number that contains the table, and then you can append the number of the table to that.
  4. First you must set up some variables so that you can determine the topic number. This code is the same code used to generate the topic title numbers in Numbering Chapters and Sections. Insert the following two lines to the top of the table title template in your custom-xsl.xsl file (above the < fo:block line):

    Step Information
    < xsl:variable name="id" select="ancestor::*[contains(@class, ' topic/topic ')][1]/@id" />  < xsl:variable name="mapTopics" select="key('map-id', $id)" /> 

    The first line finds the ID attribute of the title’s containing topic. And the second line finds the reference to that topic within the map to calculate the depth of the topic. 

  5. Next, modify the code within the < number> parameter. It should look like this:

    Step Information
    < number>    < xsl:apply-templates select="$mapTopics[1]" mode="topicTitleNumber"/>    < xsl:number level="any" count="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" from="*[@id = $id]"/>  < /number> 

    The first line (apply-templates) gets the topic number from the templates that you added in the Numbering Chapters and Sections guide. Then the xsl:number line appends the number of the table within that topic.

Your tables are numbered based on its position in the topic and the title number.
Here is the example output when using the nested numbering: