Menu

Different TOCs for sets and books

2017-11-27
2017-11-28
  • Martin Köditz

    Martin Köditz - 2017-11-27

    Hi,

    I want to create a table of contents for sets only including the book titles. Can you give me a hint where to start? Is it possible to extend the autotoc.xsl? Or is it better to create an own template?

    Currently I have a toc at the beginning of the set showing each entry of each book. But here I just need the books listed. The detailed toc should be shown in the book itself.

    Regards,
    Martin

     
    • Thomas Schraitle

      Hi Martin,

      I agree with Stefan, the autotoc.xsl file is a good start. To help you find your way, here are some additional tips.

      I want to create a table of contents for sets only including the book titles.

      Just to understand you correct, you want to change only the set TOC, but not the usual book TOC, right?

      In that case, I would try to customize the set.toc template. Replace the call for make.toc with your own code, for example:

      <xsl:template name="set.toc">
         <xsl:param name="toc-context" select="."/>
        <xsl:param name="toc.title.p" select="true()"/>
        <!-- Change the variable to your needs: -->
        <xsl:variables name="nodes" select="book|article"/>
      
        <xsl:apply-templates select="$nodes" mode="set.toc"/>
      </xsl:template>
      

      Inside the set.toc mode you use something similar to this:

      <xsl:template match="book" mode="set.toc">
        <xsl:param name="toc-context" select="."/>
      
        <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
          <xsl:call-template name="toc.line">
            <xsl:with-param name="toc-context" select="$toc-context"/>
          </xsl:call-template>
          </xsl:element>
      </xsl:template>
      

      I don't know if this does work. Try it and you will see. ;-)

      Hope this help.

      Good luck and if you have questions, just ask.

       
    • Thomas Schraitle

      If that doesn't work, here are some further explanations:

      The templates in the autotoc.xsl file operates in these two modes:

      • toc-abstract is used to create a summary for set and part elements. It uses the abstract elements to give you an additional hint about your books or parts. (This mode is created by us).
      • toc is the "normal" mode which is also used from the upstream DocBook XSL stylesheets. This mode collects all the titles from the document.

      Additionally, we've customized the folloing templates:

      • make.toc creates the complete TOC. For elements like set or part, it creates the summary used by the toc-abstract mode. For other elements, it uses the normal toc mode.
      • toc.line creates the line pointing to the respective position in the document. Usually, this template creates the HTML a element. The difference between the upstream and this element is, that it distinguish between the label (=number) and its title. This is needed to present the label with a different style than its title.
       
      • Martin Köditz

        Martin Köditz - 2017-11-28

        I will try your suggestion. I think that will take a while.

        Regards
        Martin

         
  • Stefan Knorr

    Stefan Knorr - 2017-11-27

    Uh, that is a good question. I think you are using a modified version of our SUSE stylesheets. I must admit, I think we (that is, mostly I) broke some parts of autotoc a bit. In particular, there is a ToC depth parameter, something akin to $toc.max.depth that might be helpful but is probably a bit broken in the HTML version (I don't think we ever changed much about the set ToC in the PDF version -- that use case was never quite as important to us).

    Nevertheless, I guess it is a good idea to at least start with some code from autotoc, even if you copypasta it around to somewhere else. That way, at least, most of the hard stuff is already done and you can focus on bells/whistles.

     

    Last edit: Stefan Knorr 2017-11-27

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.