More Resources
Table of Contents
More Resources
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. 

    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: