DITA and XMetaL Discussion

XMetaL Community Forum DITA and XMetaL Discussion How to add leading numbers in headings for PDF output?

  • Chartered Ham

    How to add leading numbers in headings for PDF output?

    Participants 6
    Replies 7
    Last Activity 13 years, 3 months ago

    When generating PDF output from XMetaL, I need the first two main headings to have leading numbers that specify chapter number, section, and sub-section as follows.

    For 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

    2.2 Chapter Two, Second Heading

    … and so forth.

    I know that I need to edit the “topic.topic.title” and “topic.topic.topic.title” attribute sets in custom.xsl to do this, but I'm not sure what code to use or where to start.

    Can anyone suggest how I might implement this paradigm?

    Many thanks,
    Chartered Ham

    Reply

    Chris

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

    Hi Chartered,

    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 ')]”
        level=”multiple”/>
     

    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 should get you started – you may have to tweak some of the xsl:number attributes (@from, @level, etc.) to get the exact numbering you're after.

    HTH,

    – Chris

    Reply

    Chartered Ham

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

    Chris,

    Thank you so very much for taking the time to do this. It was very much appreciated.

    Regards,
    CH

    Reply

    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 ')]”
        level=”multiple”/>
     

    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

    [text]

    2.3.4 Second Subhead Topic Title

    [text]

    2.3.4. Section Topic Title

    [text]

    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,
    C.H.

    Reply

    Chris

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

    Sorry Chartered – copy/paste error – I meant the “insertReferenceTitle” template, not the “processTopicTitle” template:

    For “insertReferenceTitle”, add a variable called “level” after the “element” variable:


     
       
     

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


     
     
       
     

     

    For your second question, I'd need more info – can you post a zip with a map and topic files that show the problem?

    – Chris

    Reply

    WinstonRV

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

    was trying your solution but can't find “insertReferenceTitle”  in my commons.xsl.
    With the gettitle i'm able to get numbering upto second level.

    Reply

    keesvandewal

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

    Hi chartered,

    I've almost the same question. I want to number my headings on level 1, 2 and 3 and the section titles:
    1.
    1.1.
    1.1.1.
    and so on.

    I've tried to implement the solution from Chris, but in this discussion your last question is not answered.

    Maybe you can tell me how you, if you have, solved the problem.

    Kind regards,
    Kees

    Reply

    IF

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

    I have been able to number headings successfully by making the template changes described here:
    http://tech.groups.yahoo.com/group/dita-users/message/19154 

    Now, I would like to revise this a bit and start numbering at the second topic. I am struggling with the syntax. I have tried to use the topic position, the topic title, or the number of preceding siblings. But I'm doing something wrong…
    Any ideas? Thanks.
    For example – adding the following to the GetTitle  template does not work







    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support