2

我有这段代码,从 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>
4

2 回答 2

2

对于仅匹配part包含的模板chapter,更改match="*[contains(@class, ' topic/topic ')]"match="part[chapter][contains(@class, ' topic/topic ')]".

[contains(@class, ' topic/topic ')]如果谓词对于您感兴趣的每一个都为真,您可能不再需要它。如果它对于您感兴趣part的任何一个都是假的,您真的不想要它。part

于 2016-03-15T21:12:13.067 回答
0

如果您想要章节级别的 minitoc,您可能还需要添加一个 OR 以便您选择章节。

于 2016-03-16T20:06:53.150 回答