Formatting Topic Titles depending on the parent

Here should go questions about transforming XML with XSLT and FOP.
josecotes
Posts: 21

Formatting Topic Titles depending on the parent

Thu Aug 16, 2018 8:25 am

Hi all,

I have a bookmap as follows:

Code: Select all

<bookmap xml:lang="en">
   <booktitle>
      <booklibrary>Title</booklibrary>
   </booktitle>
   <frontmatter>
      <preface href="preface1.xml" toc="no"/>
      <booklists>
         <toc/>
      </booklists>
   </frontmatter>
   <chapter format="ditamap" href="chapter1.ditamap"/>
   <chapter format="ditamap" href="chapter2.ditamap"/>
   <appendix format="ditamap" href="appendix1.ditamap"/>
</bookmap>


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:choose>
      <xsl:when test="parent::preface">
        <fo:block color="red"><xsl:apply-templates select="." mode="getTitle"/></fo:block>
      </xsl:when>
      <xsl:when test="parent::appendix">
        <fo:block color="green"><xsl:apply-templates select="." mode="getTitle"/></fo:block>
      </xsl:when>
      <xsl:otherwise>
        <fo:block color="blue">
            <xsl:apply-templates select="." mode="getTitle"/>
        </fo:block>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


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

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

THanks,
Costin
Posts: 428

Re: Formatting Topic Titles depending on the parent

Thu Aug 16, 2018 12:05 pm

Hello,

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

*[class~="map/topicmeta"][data-topic-id="your_topic_id_value_goes_here"]{
    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.

Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support
josecotes
Posts: 21

Re: Formatting Topic Titles depending on the parent

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.

Thanks,
Radu
Posts: 5809

Re: Formatting Topic Titles depending on the parent

Fri Aug 17, 2018 8:12 am

Hi,

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:

https://www.oxygenxml.com/forum/post40702.html#p40702

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

Code: Select all

    <topic xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot" class="- topic/topic "
        ditaarch:DITAArchVersion="1.3"
        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"
        xtrf="file:/D:/projects/eXml/samples/dita/it-book/topics/task_appendix.dita"
        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

 <appendix>
    <topicref format="ditamap" href="appendix1.ditamap"/>
 </appendix>


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.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 4 guests