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[/quote]
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":
<xsl:variable name="level" select="count(ancestor::*[contains(@class,' topic/topic ')])"/>
Now you can use the value of "level" in the choose statement - add this just before the <xsl:otherwise>:
<xsl:when test="$level = 2 or $level = 3">
<xsl:number
count="*[contains(@class, ' topic/topic ')]"
level="multiple"/><xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:when>
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:
<xsl:variable name="level">
<xsl:for-each select="$element">
<xsl:value-of select="count(ancestor::*[contains(@class, ' topic/topic ')]) + 1"/>
</xsl:for-each>
</xsl:variable>
Further down in the template, just before the <otherwise> element, modify the topic/title match:
<xsl:when test="$element/*[contains(@class, ' topic/title ')]">
<!-- Add numbering here -->
<xsl:for-each select="$element">
<xsl:number count="*[contains(@class, ' topic/topic ')]" level="multiple"/><xsl:text> </xsl:text>
</xsl:for-each>
<xsl:value-of select="string($element/*[contains(@class, ' topic/title ')])"/>
</xsl:when>
This is a problem because the "processTopicTitle" template in Commons.xsl does not contain a variable called "element" -- nor does it contain an <otherwise> 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:
<xsl:template name="getTitle"><!-- get fully-processed title content by whatever mechanism -->
<xsl:variable name="level" select="count(ancestor::*[contains(@class,' topic/topic ')])"/>
<xsl:choose>
<!-- add keycol here once implemented-->
<xsl:when test="@spectitle">
<xsl:value-of select="@spectitle"/>
</xsl:when>
<xsl:when test="$level = 2 or $level = 3">
<xsl:number count="*[contains(@class, 'topic/topic')]" level="multiple"/>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
... 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 <otherwise> 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.