Add TOC title into TOC

Post here questions and problems related to editing and publishing DITA content.
gyinshuen
Posts: 6
Joined: Tue Sep 09, 2025 11:17 am

Add TOC title into TOC

Post by gyinshuen »

Hi,
Do I have a way to insert TOC title (Contents) into DITA PDF toc? Just like the left-hand side of the image shown, the right-hand side shows my DITA PDF-CSS output.
image.png
You do not have the required permissions to view the files attached to this post.
julien_lacour
Posts: 726
Joined: Wed Oct 16, 2019 3:47 pm

Re: Add TOC title into TOC

Post by julien_lacour »

Hi,

Yes, you have the possibility to insert it, there's a use-case in our user-guide from which you can start the customization:
  1. The XSLT part is similar except <xsl:next-match/> must be called before the actual <div>:

    Code: Select all

    <xsl:template match="*[contains(@class, 'toc/title')]" mode="div-it">
      <xsl:next-match/>
      <div>
        <xsl:attribute name="class" select="'- toc/anchor anchor'"/>
        <xsl:attribute name="id" select="'toc-anchor'"/>
      </div>
    </xsl:template>
    
  2. Replace all the CSS by:

    Code: Select all

    *[class ~= "toc/anchor"] {
      content: "Contents";
      -oxy-link: "#toc-anchor";
    }
    *[class ~= "toc/anchor"]:after {
      content: leader('.') target-counter(attr(id), page);
    }
    
Regards,
Julien
Post Reply