Re: [dita-ot] Numbering sections in PDF output

792 views
Skip to first unread message
Message has been deleted

Kristen James Eberlein

unread,
Feb 2, 2015, 12:21:04 PM2/2/15
to dita-o...@googlegroups.com
We number topics (not sections) in the DITA specification.

Best,
Kris

Kristen James Eberlein
Chair, OASIS DITA Technical Committee
Principal consultant, Eberlein Consulting
www.eberleinconsulting.com
+1 919 682-2290; kriseberlein (skype)

On 2/2/2015 11:58 AM, David Goss wrote:
There doesn't seem to be an obvious way (to me) to number sections in output (e.g. 1.0, 1.1, 1.2, etc.). This also doesn't seem to be covered in Leigh White's (fantastic) Dita for Print.

I found a few dead-ends online that revolved around customizing templates in commons.xsl that don't seem to exist in DITA-OT 2.0. The most promising was this:

    <xsl:template match="*" mode="getTitle">
       
<!-- This doesn't seem to do anything -->
       
<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:for-each select="$mapTopics[1]">
               
<xsl:choose>
                   
<xsl:when test="parent::opentopic:map" />
                   
<xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ') or                                               contains(@class, ' bookmap/backmatter ')]" />
                   
<xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]">
                       
<xsl:number count="*[contains(@class, ' map/topicref ')]                                 [ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]]" format="A.1.1" level="multiple" />
                   
</xsl:when>
                   
<xsl:otherwise>
                       
<xsl:number count="*[contains(@class, ' map/topicref ')]                                 [not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]" format="1.1" level="multiple" />
                   
</xsl:otherwise>
               
</xsl:choose>
           
</xsl:for-each>
       
</fo:inline>
       
<xsl:text> </xsl:text>
       
<xsl:apply-templates />
   
</xsl:template>

This seemed to have no affect in the output, but looks otherwise ok/logical to me.

Has anyone successfully gotten section number in PDFs, and if so how?


--
You received this message because you are subscribed to the Google Groups "DITA-OT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Goss

unread,
Feb 2, 2015, 12:24:17 PM2/2/15
to dita-o...@googlegroups.com
I do mean numbering topics--It slipped my mind that there is an actual <section> element. My question is referring to numbering topics that the href of topicrefs in the map file.

Anurag Srivastava

unread,
Jun 22, 2018, 2:11:15 AM6/22/18
to DITA-OT Users
Hi,

My work requires creation of a PDF using external DITA-OT. But there’s a demand to create the TOC with numbered chapters, topics, and sub-topics (drilling-down to 5 or 6 levels). Attaching the screen for your reference (this is what I need TOC to be like, highlighted in red):

 


 

Can you please help and guide me how can I obtain this through DITA-OT?

 

I tried modifying custom.xsl but it is not yielding results as expected.

 

Looking forward to your reply.

 

Best regards,

 

Anurag Srivastava

Michael Morrison

unread,
Jun 22, 2018, 3:48:50 PM6/22/18
to DITA-OT Users
Check out the PDF Plugin Generator; it includes an option "Title Numbering" for Heading styles.

In the generated xsl/fo/commons.xsl file (for DOT 3.0 with FOP), it includes the following XSL to generate numbered headings:

 <!--title numbering-->
 
<xsl:variable name="e:number-levels" select="(true(), true(), true(), true())" />
 
<xsl:template match="*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]" 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:for-each select="$mapTopics[1]">

       
<xsl:variable name="depth" select="count(ancestor-or-self::*[contains(@class, ' map/topicref')])" />
       
<xsl:choose>
         
<xsl:when test="parent::opentopic:map and contains(@class, ' bookmap/bookmap ')" />
         
<xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ') or&#xA;                                              contains(@class, ' bookmap/backmatter ')]" />
         
<xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/appendix ')] and&#xA;                          $e:number-levels[$depth]">
           
<xsl:number count="*[contains(@class, ' map/topicref ')]&#xA;                                [ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]] " format="A.1.1" level="multiple" />
         
</xsl:when>
         
<xsl:when test="$e:number-levels[$depth]">
           
<xsl:number count="*[contains(@class, ' map/topicref ')]&#xA;                                [not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]" format="1.1" level="multiple" />
         
</xsl:when>

       
</xsl:choose>
     
</xsl:for-each>
   
</fo:inline>

   
<xsl:value-of select="' '" />

   
<xsl:apply-templates />
 
</xsl:template>

Hope that helps!

Cheers,
Michael
Message has been deleted

Anurag Srivastava

unread,
Jun 26, 2018, 1:26:49 AM6/26/18
to DITA-OT Users
Hi Michael,

Thank you so much.

It worked. I had to do some modifications to the code-snippet you provided to work on the local env.

I had to comment/remove the e:number-levels instances as it was resulting in build error.

Here's the code I tried (and that worked on my machine):

<!-- <xsl:variable name="e:number-levels" select="(true(), true(), true(), true())" /> -->
  <xsl:template match="*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]" 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:for-each select="$mapTopics[1]">
        <xsl:variable name="depth" select="count(ancestor-or-self::*[contains(@class, ' map/topicref')])" />
        <xsl:choose>
          <xsl:when test="parent::opentopic:map and contains(@class, ' bookmap/bookmap ')" />
          <xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ') or&#xA;                                              contains(@class, ' bookmap/backmatter ')]" />
          <xsl:when test="ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]">
            <xsl:number count="*[contains(@class, ' map/topicref ')]&#xA; 
[ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]] " format="A.1.1" level="multiple" />
          </xsl:when>   
<xsl:otherwise>
<xsl:number count="*[contains(@class, ' map/topicref ')]&#xA;         
                       [not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]" format="1.1" level="multiple" />
</xsl:otherwise>
         <!--  <xsl:when test="$e:number-levels[$depth]">
            <xsl:number count="*[contains(@class, ' map/topicref ')]&#xA;  
                              [not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]" format="1.1" level="multiple" />
          </xsl:when>
 -->
        </xsl:choose>
      </xsl:for-each>
    </fo:inline>
    <xsl:value-of select="' '" />
    <xsl:apply-templates />
  </xsl:template>

Thanks again.

Best regards,

- Anurag Srivastava

Rick Smith

unread,
Aug 4, 2022, 2:10:01 PM8/4/22
to DITA-OT Users
This work charm with <chapter><topic> format but when I am using this solution for <part><chapter><topic> structure. The chapter and topic is restarting for each part. 
For example:

Part 1
    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4

Part 2
    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4

While it actually should be:

Part 1
    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4

Part 2
    Chapter 5
    Chapter 6
    Chapter 7
    Chapter 8

Any Idea, what should be done to continue chapter numbering.

Reply all
Reply to author
Forward
0 new messages