我正在使用 wkhtmltodpf 和 knp-snappy,我试图将 TOC 限制为最多 3 个孩子。我已经定义了如下所示的自定义 xsl 文件:
<xsl:template match="outline:outline">
<html>
<head>
</head>
<body>
<h1>Table of Contents</h1>
<ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
</body>
</html>
</xsl:template>
<xsl:template match="outline:item">
<li class="level-{count(ancestor::*) - 1}">
<xsl:if test="((@title!='') and (@title!='Table of Contents'))">
<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>
<ul class="level-{count(ancestor::*) - 1}">
<xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
<xsl:apply-templates select="outline:item"/>
</ul>
</li>
</xsl:template>
并输出:
我只需要显示 1,2,3 级别我不擅长 XML,我真的不知道如何限制它:/ 我正在使用这些标签来创建我的目录:
1 - h4 标签 2 - h3 标签 3 - h2 标签 ...