Formatting Topic Titles depending on the parent

Here should go questions about transforming XML with XSLT and FOP.
Posts: 21
Joined: Wed Nov 18, 2015 6:43 pm

Formatting Topic Titles depending on the parent

Post by josecotes » Thu Aug 16, 2018 8:25 am

Hi all,

I have a bookmap as follows:

Code: Select all

<bookmap xml:lang="en">
<preface href="preface1.xml" toc="no"/>
<chapter format="ditamap" href="chapter1.ditamap"/>
<chapter format="ditamap" href="chapter2.ditamap"/>
<appendix format="ditamap" href="appendix1.ditamap"/>
I'd like the titles on the preface to be red, the chapters to be blue and the appendix to be green. Here is my approach but it is not working for some reason:

Code: Select all

<xsl:template match="*" mode="processTopicTitle">
<xsl:when test="parent::preface">
<fo:block color="red"><xsl:apply-templates select="." mode="getTitle"/></fo:block>
<xsl:when test="parent::appendix">
<fo:block color="green"><xsl:apply-templates select="." mode="getTitle"/></fo:block>
<fo:block color="blue">
<xsl:apply-templates select="." mode="getTitle"/>
At the moment all the titles are blue. It seems that the test fails and executes the otherwise.

Any clue?

On a related note. How do I not include the preface in the TOC and the Bookmarks? Inside the preface, I have different topics. With

Code: Select all

the first main topic is not included, but the subtopics are included. I would like the entire preface to be ignored.


Posts: 697
Joined: Mon Dec 05, 2011 6:04 pm

Re: Formatting Topic Titles depending on the parent

Post by Costin » Thu Aug 16, 2018 12:05 pm


You should use the DITA Map PDF - based on HTML5 and CSS instead of the DITA Map PDF (based on XSL-FO) transformation scenario.
That's because it is easier to fine tune how specific elements are rendered in the output, or if they would be rendered at all, by styling/hiding them through CSS properties ("display: none;" for example, set on specific selectors). You just need basic CSS knowledge.

You should just publish your DITA Map to PDF using the CSS and HTML5 scenario, then open the resulted merged.html file from the output directory in your internet browser and use the browser's CSS inspector to identify the selectors that correspond to elements that you want to style or hide (preface, chapter and appendix titles, as well as references from the TOC).

For example, to style the preface / topic / appendix titles with different colors, you could use:

Code: Select all

*[class~="nested0"][oid*="preface"] > *[class~="topictitle1"]{
color: red;

*[is-chapter="true"] > *[class~="topictitle1"]{
color: blue;

*[class~="nested0"][oid*="appendix"] > *[class~="topictitle1"]{
color: green;
In a similar fashion, you should identify the specific selectors for the TOC elements you need to hide in the resulted PDF and apply your rules on them (like "display: none;" if you want them hidden from the toc).
For example, you could use rules like:

Code: Select all

display: none;
To learn how you can identify the specific selectors in the merged.html output in order to use them in your own CSS and apply the rules you need, you should read the Debugging the CSS section from the "DITA-OT CSS Publishing to PDF Plugin" User-Guide.

Costin Sandoi
oXygen XML Editor and Author Support

Posts: 21
Joined: Wed Nov 18, 2015 6:43 pm

Re: Formatting Topic Titles depending on the parent

Post by josecotes » Thu Aug 16, 2018 9:07 pm

Hi Costin,

Thanks for the reply. But is there a way to do this using XSL-FO? We have very old plugins that I don't want to re-write into CSS plugins.


Posts: 7032
Joined: Fri Jul 09, 2004 5:18 pm

Re: Formatting Topic Titles depending on the parent

Post by Radu » Fri Aug 17, 2018 8:12 am


In general when writing an XPath expression you should know how the matched XML content looks like.
If you edit the Oxygen transformation scenario and in the Parameters tab set the parameter "clean.temp" to "no", then publish, after the transformation, in the transformation temporary folder there should be a "mapName_MERGED.xml" file which is the XML on which your customization XSLT is applied. You can open it in Oxygen and look at its structure.
In the MERGED.xml there is an "opentopic:map" which contains some kind of topicref structure of the original DITA Map and after this element all the topics are expanded in place. More details about how the MERGED.xml is structured can be found here:


The title matched by your XSLT template has a parent topic element, something like this:

Code: Select all

    <topic xmlns:dita-ot="" class="- topic/topic "
domains="(topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d) "
xml:lang="en-us" xtrc="topic:1;8:44"
oid="task_appendix" id="unique_27">
<title class="- topic/title " xtrc="title:1;9:8"
xtrf="file:/D:/projects/eXml/samples/dita/it-book/topics/task_appendix.dita">Sample Appendix</title>
and that parent topic element has an "@id" attribute value. You need to use an XPath and find in the same XML file the topicref which has the same @id attribute value and that topicref will give you details about where the topic was referenced in the DITA Map.
The problem with using a construct like this:

Code: Select all

 <appendix format="ditamap" href="appendix1.ditamap"/>
is that references to other DITA Maps are transparently expanded in place and the "appendix" element will simply be replaced with the referenced dita map's contents. So you could try this approach instead:

Code: Select all

<topicref format="ditamap" href="appendix1.ditamap"/>
and see how this looks like in the _MERGED.xml file. It helps if you create a small test DITA project for this, containing only the main DITA Map, a reference to another DITA Map and a single topic, just to obtain a very simple "_MERGED.xml" file.

An alternate approach would be to set the @outputclass attribute directly on the root element for all DITA topics which are contained in the appendix and match titles which have parent elements containing that specific @outputclass attribute value.

Radu Coravu
<oXygen/> XML Editor

Post Reply