Ignore titles from being rendering into the TOC summary

107 views
Skip to first unread message

Ahmed EBEN HASSINE

unread,
Mar 11, 2022, 11:11:57 AM3/11/22
to wkhtmltopdf General
I'm using `wkhtmltopdf` toc feature, to generate a dynamic summary. Is there a way to avoid the rendering of h1, h2, h3, h4 tags in case there is an `"ignore"` class attached to the hn tag ?

For example, if we have:
`<h1 class="ignore">First Title</h1>` inside my HTML markup, this title should not be added to my summary.<br>
HTML:

    <h1 class="ignore">First Title</h1>
    <h1 >Second Title</h1>

Result:

    Second Title --------------------- Page x

This is my toc.xls:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:outline="http://wkhtmltopdf.org/outline"
                    xmlns="http://www.w3.org/1999/xhtml">
        <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
                    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona
    l.dtd"
                    indent="yes" />
        <xsl:template match="outline:outline">
            <html>
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <style>
                        h1 {
                        text-align: center;
                        font-size: 20px;
                        font-family: arial;
                        }
                        div {border-bottom: 1px dashed rgb(200,200,200);}
                        span {float: right;}
                        li {list-style: none;}
                        ul {
                        font-size: 20px;
                        font-family: arial;
                        }
                        ul ul {font-size: 80%; }
                        ul {padding-left: 0em;}
                        ul ul {padding-left: 1em;}
                        a {text-decoration:none; color: black;}
                    </style>
                </head>
                <body>
                    <ol><xsl:apply-templates select="outline:item/outline:item"/></ol>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="outline:item">
          <li>
            <xsl:if test="@title!=''">
              <div>
                <a>
                  <xsl:if test="@link">
                    <xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
                  </xsl:if>
                  <xsl:if test="@backLink">
                    <xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="@title" />
                </a>
                <span> <xsl:value-of select="@page" /> </span>
              </div>
            </xsl:if>
            <ol>
              <xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
              <xsl:apply-templates select="outline:item"/>
            </ol>
          </li>
        </xsl:template>
    </xsl:stylesheet>




Jonathan Rynd

unread,
Apr 1, 2022, 8:25:42 AM4/1/22
to wkhtmltopdf General
Have you tried editing the css in the style tag of the toc file to have an entry for .ignore { display: none }
Reply all
Reply to author
Forward
0 new messages