Changing Headings without Changing ToC

Here should go questions about transforming XML with XSLT and FOP.
Posts: 4
Joined: Wed May 25, 2016 6:43 pm

Changing Headings without Changing ToC

Post by Cmarine » Wed May 25, 2016 6:53 pm


I am trying to make some changes to the alignment of my headings in PDF without affecting the ToC. Specifically, I want the heading number to be left aligned, and I want the heading name to be aligned with the body text. For example...

1.2 Making Jam
The art of making jam is....

I am able to achieve this one by altering the following XSL that controls the autonumbering
[Codebox=] <xsl:variable name="e:number-levels" select="(true(), true(), true(), true())" />
<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 space-end="15pt">
<xsl:for-each select="$mapTopics[1]">
<xsl:variable name="depth" select="count(ancestor-or-self::*[contains(@class, ' map/topicref')])" />
<xsl:when test="parent::opentopic:map and contains(@class, ' bookmap/bookmap ')" />
<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 ')] and $e:number-levels[$depth]">
<xsl:number count="*[contains(@class, ' map/topicref ')] [ancestor-or-self::*[contains(@class, ' bookmap/appendix ')]] " format="A.1.1" level="multiple" />
<xsl:when test="$e:number-levels[$depth]">
<xsl:number count="*[contains(@class, ' map/topicref ')] [not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]" format="1.1" level="multiple" />

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

If I add the "space-end" attribute to the <fo:inline> tag as I have done in the example, I get the separation I am looking for. However, this also affects the ToC output which doesn't look as good.

Any thoughts on how I can affect the one and not the other? Thanks!

Posts: 375
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova

Re: Changing Headings without Changing ToC

Post by radu_pisoi » Thu May 26, 2016 10:46 am


A solution is to add a parameter (disableNumbering for instance) in your customization template to control if the numbering is computed.

I think the template responsible for computing the titles for TOC is 'getNavTitle' from /DITA-OT/plugins/org.dita.pdf2/xsl/fo/commons.xsl. So, you need to also override this template and modify it to set the 'disableNumbering' to 'false' when it computes the title.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Post Reply