Modifying header title size for topics in HTML output

Oxygen general issues.
jnielsen
Posts: 58
Joined: Fri Sep 12, 2008 12:12 am

Modifying header title size for topics in HTML output

Post by jnielsen »

At my worksplace we are using an alternate version of dita2html.xsl that puts all the content on a single page - instead of generating a main page with the TOC which you then click on various links to get to the individual topics on their own page - so now the default sizing of the topic header titles has become a problem in that they are all the same size (huge to say the least), and do not refelect the hierarchy in the ditamap. I was trying to investigate a way to alter this by looking for any relevant section in dita2htmlImpl.xsl and found a section from lines 277-294 that mention the heading size, but I'm not sure if this can be modified for our purposes.

In its comments section it says:

Code: Select all

<!-- NESTED TOPIC TITLES (sensitive to nesting depth, but are still processed for contained markup) -->
<!-- 1st level - topic/title -->
<!-- Condensed topic title into single template without priorities; use $headinglevel to set heading.
If desired, somebody could pass in the value to manually set the heading level -->
and also has a modifiable section here (lines 283-286):

Code: Select all

<xsl:choose>
<xsl:when test="count(ancestor::*[contains(@class,' topic/topic ')]) > 6">6</xsl:when>
<xsl:otherwise><xsl:value-of select="count(ancestor::*[contains(@class,' topic/topic ')])"/></xsl:otherwise>
</xsl:choose>
But I am unsure what the 6 refers to. Is it checking the nesting depth? Aside from that though, am I even barking up the right tree? Is there any way you can think of to specify to DITA that topic headings should be sized differently based on their hierarchical position in the ditamap?

Thanks for your input.

~Josh
Radu
Posts: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Modifying header title size for topics in HTML output

Post by Radu »

Hi Josh,

You are indeed near the XSLT code which does that.

There should be a code fragment which specifies:

Code: Select all


<xsl:element name="h{$headinglevel}">
<xsl:attribute name="class">topictitle<xsl:value-of select="$headinglevel"/></xsl:attribute>
<xsl:call-template name="commonattributes"/>
<xsl:apply-templates/>
</xsl:element>
The {$headinglevel} variable actually specifies the index of the heading to set in the output (h1, h2....etc) depending on the nesting of the current topic in the whole document.

For example, if you replace {$headinglevel} with a hardcoded 3 you will always have <h3> used for topic titles regardless of the imbrication.

It's probably better to make a fix in the place where the headinglevel is computed and increase it by 1 for example. In this way, your topic titles will begin with <h2> and increase depending on the imbrication.

This fix should look like:

Code: Select all


<xsl:param name="headinglevel">
<xsl:choose>
<xsl:when test="count(ancestor::*[contains(@class,' topic/topic ')]) > 6">6</xsl:when>
<xsl:otherwise><xsl:value-of select="count(ancestor::*[contains(@class,' topic/topic ')]) + 1"/></xsl:otherwise>
</xsl:choose>
</xsl:param>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jnielsen
Posts: 58
Joined: Fri Sep 12, 2008 12:12 am

Re: Modifying header title size for topics in HTML output

Post by jnielsen »

Thank you, that did decrease the header size a bit, although I still need to get something straight. From looking at the code it looks like the idea is to discover a topic's depth in the hierarchy tree by using ancestor::* and if you are at the root level it returns 1 (H1 being the largest font size), a child of the root gets H2, a child of that gets H3, etc. So in theory the size decreases for each child based on its tree depth, correct? If so then it is not functioning that way. I have children topics on the third "rung" of the tree that have headers that are just as large as the header text for its parent and the root topic above that. Is there a reason this is not working? Have I misunderstood how the header size code is supposed to work?

Thanks,

Josh
Radu
Posts: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Modifying header title size for topics in HTML output

Post by Radu »

Hi Josh,

Indeed this is the way in which that XSLT code should work.
If in the HTML file you select a topic title which should be smaller and then right click and "Show Source" (the action is available in Firefox) what is the header used to render that topic title?

You can also add some xsl:messages in the XSLT code and find out more about the way the header is computed.

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