我有这段代码,从 DITA-OT 原始发行版修改而来:
<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="in-this-section-chapter-list">
<fo:block margin-left="6em">
<fo:block>
<xsl:call-template name="insertVariable">
<xsl:with-param name="theVariableID" select="'Chapter with number'"/>
<xsl:with-param name="theParameters">
<number>
<fo:inline>
<xsl:apply-templates select="key('map-id', @id)[1]"
mode="topicTitleNumber"/>
</fo:inline>
</number>
</xsl:with-param>
</xsl:call-template>
</fo:block>
</fo:block>
</xsl:template>
我试图只执行/打印这个迷你目录,当这是一个以章节作为子节点的部分时(见下文),但不是当它只是一个没有任何章节的部分时,在这样的书中:
<?xml version="1.0" encoding="utf-8"?>
<bookmap>
<part>
<chapter/>
<chapter/>
<chapter/>
</part>
<part/>
<part/>
<part/>
<part/>
<appendix/>
</bookmap>
所以在这种情况下,只有第一个<part>会执行/打印这个。
我认为将<xsl:apply-templates select="key('map-id', @id)[1]" mode="topicTitleNumber"/>的值作为文本传递,可以让我基本上添加一个if将测试一个不为空的值,从而执行它。但它没有奏效。
我想出了这样的东西,这是无效的:
<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="in-this-section-chapter-list">
<xsl:with-param name="value-number">
<xsl:apply-templates select="key('map-id', @id)[1]"
mode="topicTitleNumber"/>
</xsl:with-param>
<xsl:if test="$value-number!=''">
<fo:block margin-left="6em">
<fo:block>
<xsl:call-template name="insertVariable">
<xsl:with-param name="theVariableID" select="'Chapter with number'"/>
<xsl:with-param name="theParameters">
<number>
<fo:inline>
<xsl:apply-templates select="key('map-id', @id)[1]"
mode="topicTitleNumber"/>
</fo:inline>
</number>
</xsl:with-param>
</xsl:call-template>
</fo:block>
</fo:block>
</xsl:if>
</xsl:template>