Hi Jennifer,

Can you tell me what version of DocBook XSL your customization is based on?  The <p class="toc"> element was replaced by <div class="toc"> quite awhile ago.

In general, the way it works is that the document is processed again in mode="toc".  Instead of the normal processing of an element to format its content, the mode="toc" processes the element to generate just an entry in the TOC for that element by formatting its title inside an <a> link whose @href points to that element's content.  You'll find in html/autotoc.xsl a set of templates matching on different elements and with the attribute mode="toc", such as this one:

<xsl:template match="preface|chapter|appendix|article" mode="toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="subtoc">
    <xsl:with-param name="toc-context" select="$toc-context"/>
    <xsl:with-param name="nodes" select="section|sect1
|bridgehead[$bridgehead.in.toc != 0]"/>
  </xsl:call-template>
</xsl:template>

The $nodes parameter is a list of the children of the current element that should be included as a sublist under that element's TOC line.

The template that does all the work is named "subtoc".  It is in subtoc where you will find the code that generates a line in the TOC:

<a>
      <xsl:attribute name="href">
        <xsl:call-template name="href.target">
          <xsl:with-param name="context" select="$toc-context"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:apply-templates select="." mode="title.markup"/>
</a>

The order of processing in subtoc is a bit confusing, because it processes the children first into a temporary subtoc.list variable, then outputs the TOC line followed by that subtoc list variable.

The handling of <dl> has always been a bit inconsistent across browser versions.  In more recent versions of the stylesheet there is a stylesheet param named 'toc.list.type' which lets you replace <dl><dd><dt> with <ul><li>.  You can use CSS to turn off the bullets for the <ul> list.    Does your version of html/autotoc.xsl have a line like this:

              <xsl:element name="{$toc.list.type}">

If so, then you can replace <dl>, which might solve some of your formatting problem.

Bob Stayton
b...@sagehill.net

On 6/30/2020 10:38 AM, Jennifer Moore wrote:
Hi folks

On a hunt for which template I need to tweak for a table of contents in an article.  A clue or two from someone more expert would help!

Context is, I've got an old copy of oXygen, and I use some slightly-customised XSL to convert DocBook 5 to HTML, for blog posts.

I haven't needed to change any of the XSL for some years now, so I'd semi-forgotten what I used to know about that when I set it up - which even at the time was not a huge amount - but have re-reminded myself of some, by re-reading bits of Bob's book and posts I made to the lists at the time :-)

Today's problem:

When writing articles, usually I've used <section>.  Now I've added <section> within <section>.

In the auto-generated HTML table of contents, the layout now isn't quite right - it's adding some line breaks I don't want, and losing the font size part way through.

So I thought I'd get into the template and see what it's doing, and see if I can work out how to adjust it to my liking.

Step 1, find out which template is doing that bit!

The post-transform HTML contains some <dd> tags to create an indent for the lower-level sections, which seems like it could be a clue as to what the relevant bit of XSL will look like when I find it.  So I tried searching on <dd>.  But it turns out <dd> appears in quite a lot of the XSL files, so that's not enough of a clue for me to work out which one :-)

I do know which template is _calling_ the bit I'm interested in:

<xsl:template name="make.toc">

It sets up the "outer layer" of the ToC, and it's in an already-slightly-customised file for ToCs which is an adaptation of, I think, autotoc.xsl.

By looking at this previously-customised make.toc, and sticking in some dummy classes to see what appeared where in the HTML, I was able to deduce that the part of it that's actually doing the work (in this case) is this:

<xsl:otherwise>
  <xsl:if test="$nodes">
    <p class="toc">
      <xsl:copy-of select="$toc.title"/>
      <xsl:apply-templates select="$nodes" mode="toc">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </p>
  </xsl:if>
</xsl:otherwise>

If I understand correctly, apply-templates is what tells the middle bit of the ToC to be assembled by a different template somewhere else, or several different templates.

I get that the with-param tag is passing a variable through to the other templates.

select="$nodes" mode="toc" is unfamiliar to me, I'm not sure what that's doing.

Logically, I assume that somewhere along the way, as well as creating the layout of the list, it's also taking the <title> and the xml:id of each <section>, and using those to assemble a link.  That bit of transformation could be happening in a different template from the one I need to tweak, though.

Any clues about finding it?

Thanks!

Jennifer

Reply via email to