Home Forums DITA and XMetaL Discussion How to add leading numbers in headings for PDF output? Reply To: How to add leading numbers in headings for PDF output?

Chartered Ham

Reply to: How to add leading numbers in headings for PDF output?

Hi Chris,

Once again, thanks for the solution to my question. Unfortunately, it turned out to be only a partial solution, for a couple of different reasons.

Just to recap briefly, my question was about how to add leading numbers to first- and second-level headings in PDF output, as follows in this example:

  1.1  Chapter One, First Heading

  1.2  Chapter One, Second Heading

      1.2.1  Chapter One, First Subheading of Second Heading

      1.2.2  Chapter One, Second Subheading of Second Heading


  2.1  Chapter Two, First Heading

You responded as follows:

To add numbering to topic titles, you will have to override two XSL templates from [xmfo]/xsl/fo/commons.xsl:

“processTopicTitle” from ~line 580, and “getTitle” from ~1220.

The “getTitle” override controls display in the body text and TOC, and “processTopicTitle” renders the link text for inline xrefs.

Copy both of these templates into your customization file: [xmfo]/Customization/fo/xsl/custom.xsl

1. For “getTitle”, add a variable called “level”:

Now you can use the value of “level” in the choose statement – add this just before the :

      count=”*[contains(@class, ' topic/topic ')]”

The first part about modifying the getTitle template worked. We modified our Custom.xsl file using this suggestion.

For the second part of your tip, however, you wrote:

2. For “processTopicTitle”, add a variable called “level” after the “element” variable:


Further down in the template, just before the element, modify the topic/title match:



This is a problem because the “processTopicTitle” template in Commons.xsl does not contain a variable called “element” — nor does it contain an element.

Luckily, we were able to work around this by partially implementing your fix by modifying the end of my Custom.xsl file as follows:






… so it still works. The first- and second-level headings in my PDF output have leading numbers.

This breaks, however, when inserting a subtopic or section within a topic that turns out to be at the first- or second-level heading within the ditamap. The subtopic or section title inherits the leading number — something we don't want to happen.

For example, if I have a second-level heading topic at a numbering level of, say, 2.3.4, any subtopic or section within that topic will also have the same numbering level “2.3.4” appended onto the front of it. Like this:

2.3.4. Topic Title

2.3.4. Subhead Topic Title


2.3.4 Second Subhead Topic Title


2.3.4. Section Topic Title


Not good, obviously.

My questions are:

  • Can you clarify what you meant in item 1 about the “element” variable and the element?
  • Can you suggest how I might fix the coding so that subtopic and section titles don't inherit the leading numbers of their parent topics?

I know this is asking a lot, so I appreciate any response you might be willing to offer.

Thank you!

Sincere Regards,