【问题标题】:Remove specific title from TOC generated from wkhtmltopdf从 wkhtmltopdf 生成的 TOC 中删除特定标题
【发布时间】:2021-07-18 23:53:14
【问题描述】:

我有几个以标题和作者姓名开头的 html 文件,但我不希望它们出现在目录中。我使用remove toc from toc in wkhtmltopdf 硬编码要删除的 h1/h2 的值,但我希望 xlst toc 文件独立于文档名称和作者。

所以我给这些特定的标题一个类属性。问题出在 xlst 过滤器上,我没有找到测试或提取类属性的方法。

这是html文件的一部分:

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

这里是 xslt toc 文件部分:

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

我是 xslt 的新手,不知道 outline:item 到底是什么,但它似乎没有得到原始的类属性。我怎样才能完成这项工作?

【问题讨论】:

    标签: xslt wkhtmltopdf


    【解决方案1】:

    一个简单的解决方案是使用div 标签而不是标题。在您的 CSS 中,确保指定 display: block;

    【讨论】:

      【解决方案2】:

      如果你运行

          --dump-outline toc.xml 
      

      生成 pdf 时标记并查看 xml 文件,您将看到 xml 节点和属性。

      然后您可以测试文档的标题、页码、链接和反向链接。您可以将这些属性用于您的 if 语句。

      例如:

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

      注意完整测试的括号。

      如果需要,您甚至可以进一步嵌套 if 语句:

      <xsl:if test="((@page!=1) and (@page!=2) and (@page!=5))">
          <xsl:if test="(@title!='A title')">
            more code
          </xsl:if>
      </xsl:if>
      

      【讨论】:

      • 有没有办法使用@class@属性?
      猜你喜欢
      • 2011-04-17
      • 2022-08-22
      • 2012-10-19
      • 2011-08-14
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多