DITA-FMx always uses the <title> element in a topic file to generate title text in both XHTML and PDF outputs (regardless, for example, of the value of the navtitle attribute on the corresponding <topicref> element in the ditamap, and regardless of the value of the locktitle attribute).
I wanted a way to have one title on my HTML help pages and optionally a different one in the PDF file I generated using DITA-FMx's Generate Book from Map command.
I decided to use the <navtitle> element under <titlealts> ("alternative titles") in topic files to specify an alternative title for PDF output. I'm not too sure that this is DITA-compliant, but it works a charm. There's no support for this element in the default structured applications supplied with DITA-FMx, so I needed to make some modifications.
1. I edited the EDD of the DITA-Topic-FM structured application (which is just used to format text while you are authoring a topic), and added some formatting for the <titlealts> element, for example, 12pt, Red, and Bold. I also added a Prefix to remind me what it was for!
2. I edited the ditamap2fmbook.xsl file of the DITA-Book-FM structured application (which is used to format text for the FrameMaker book generated using the Generate Book from Map command). As its title suggests, this file translates a ditamap into a FrameMaker book. In fact, it only accomplishes the first stage of the conversion process, namely to generate a single XML file that includes all the ditamap and topic file content. This file is then further processed by FrameMaker's Read/Write Rules and converted to FM files.
Editing this XSL file is unfortunately not too straightforward. I needed to make sure that whenever a <navtitle> element is found in a topic file, its text is to be written into the generated XML file as the <title> element in place of the default, top-level <title> element. Here is the key part of the modified XSL:
<xsl:template match="title">
<title>
<xsl:choose>
<xsl:when test="following-sibling::titlealts/navtitle">
<xsl:copy-of select="@*">
<xsl:value-of select="following-sibling::titlealts/navtitle/text()">
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="@*node()">
</xsl:otherwise>
</xsl:choose>
</title>
</xsl:template>
So when the <title> element is followed by a sibling <titlealts> element that has a child <navtitle> element, write that element's text into the <title> element instead. Otherwise, just use the <title> element's text as usual.
Now when I want a different bookmark and heading in my PDF, I just add a <navtitle> element to my topic file, and set the locktitle attribute to "yes" in the <topicref> element of the ditamap that references the topic file. If I set the locktitle attribute back to "no", the <navtitle> is ignored and the default title text is used instead.
No comments:
Post a Comment