'Exclude titles from being rendering into the TOC summary

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.
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>


Solution 1:[1]

I think there are two ways to accomplish this:

  1. Don't use an hn tag for those headers you want to hide from toc. Create css classes that imitate the style of the corresponding hn tags (e. g. .h1 .h2 and so on). Then turn <h2 class="ignore">Lorem ipsum</h2> into <div class="h1">Lorem ipsum</div>.

  2. Add a class definition to your toc styles:

    .ignore { display: none; }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1