2

I have several html files starting with a title and the author name, but I don't want them in the table of content. I used remove toc from toc in wkhtmltopdf to hard code the value of the h1/h2 to remove but I would like the xlst toc file to be independent of the name of the document and the author.

So I gave these specific titles a class attribute. The problem lies in the xlst filter, I didn't find a way to test or extract the class attribute.

Here is a part of the html file :

<h1 class="title">Me</h1> 
<h2 class="author">My Title</h2>

Here is the xslt toc file part :

<xsl:template match="outline:item">
    <li>
        <xsl:if test="(@title!='') and (@title!='My little TOC')and (@class!='author')and (@class!='title')">

I'm a total newbie to xslt and don't know what outline:item really is, but it seems that it doesn't get the original class attribute. How could I get the job done ?

41 72 6c
  • 1,600
  • 5
  • 19
  • 30
Fericelli
  • 320
  • 3
  • 9

2 Answers2

1

One simple solution is to use div tags instead of headings. In your CSS, make sure you specify display: block;.

Bob Sutor
  • 71
  • 5
-1

if you run the

    --dump-outline toc.xml 

flag when you generate the pdf and look at the xml file you will see the xml nodes and attributes.

You can then test for either the title, page number, link and backlink the document. You can use these attributes for your if statment.

For example:

  <xsl:if test="((@page!=1) and (@page!=2) and (@page!=5))">
     blah blah blah
  </xsl:if>

Note the brackets around the full test.

You can even then nest the if statements further if needed:

<xsl:if test="((@page!=1) and (@page!=2) and (@page!=5))">
    <xsl:if test="(@title!='A title')">
      more code
    </xsl:if>
</xsl:if>
CherryDT
  • 25,571
  • 5
  • 49
  • 74
MrsPop88
  • 303
  • 4
  • 14