1

我有这个书图:

<?xml version="1.0" encoding="utf-8"?>
<bookmap>
<part>
    <chapter/>
    <chapter/>
    <chapter/>
</part>
<part/>
<part/>
<part/>
<part/>
<appendix/>
</bookmap>

我想在模板中放置 xsl:if 命令,这些命令取决于元素是part/chapter还是part.

即我在 template 中有这些processTopicTitle,是 DITA-OT 发行版的一部分:

<xsl:if test="bookmap/part/chapter">
    <fo:external-graphic src="thisischapter.png" />
</xsl:if>

<xsl:if test="bookmap/part">
    <fo:external-graphic src="thisispart.png" />
</xsl:if>

这是行不通的。

这个想法是,有一个图形只显示在part/chapters中,另一个显示在那些只是part的图形上。

4

2 回答 2

2

你需要做的是这样的:

<xsl:choose>
    <!-- parts -->
    <xsl:when test="$map//*[contains(@class, ' bookmap/part ')]">
        <xsl:call-template name="getVariable">
            <xsl:with-param name="id" select="'First Cover Image Path'"/>
        </xsl:call-template>
    </xsl:when>
    <!-- chapters -->
    <xsl:when test="$map//*[contains(@class, ' bookmap/chapter ')]">
        <xsl:call-template name="getVariable">
            <xsl:with-param name="id" select="'Second Cover Image Path'"/>
        </xsl:call-template>
    </xsl:when>
    <!-- parts without chapters -->
    <xsl:when test="$map//*[contains(@class, ' bookmap/part ')][not(child::*[contains(@class, ' bookmap/chapter ')])">
        <xsl:call-template name="getVariable">
            <xsl:with-param name="id" select="'Third Cover Image Path'"/>
        </xsl:call-template>
    </xsl:when>
</xsl:choose>

您应该在配置文件中定义图像~/cfg/common/vars/en.xml

你应该阅读:

更新

要放置图像,您应该使用placeImage模板:

<xsl:apply-templates mode="placeImage" select=".">
    <xsl:with-param name="imageAlign" select="@align"/>
    <xsl:with-param name="href"
                    select="
                    if (@scope = 'external' or opentopic-func:isAbsolute(@href)) then
                        @href
                    else
                        concat($input.dir.url, @href)"/>
    <xsl:with-param name="height" select="@height"/>
    <xsl:with-param name="width" select="@width"/>
</xsl:apply-templates>

使用dita-generator生成插件,设置自定义封面图像,然后将您的代码与生成的插件的代码进行比较会很有帮助。

于 2016-03-30T09:57:33.203 回答
0

我让它像这样工作:

<xsl:template name="insertDiamond">
    <xsl:variable name="topicref" select="key('map-id', ancestor-or-self::*[contains(@class,' topic/topic ')][1]/@id)"/>
    <xsl:choose>
        <xsl:when test="$topicref//ancestor-or-self::*[contains(@class, ' bookmap/part ')][not(child::*[contains(@class, ' bookmap/chapter ')])]">
            <!--Put actions here for parts without any chapters as childs-->
        </xsl:when>
        <xsl:otherwise>
            <!--Put actions here for the rest.-->
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
于 2016-04-08T05:03:09.627 回答