xsl:if 取决于子节点
xsl:if that depends on a child node
我有这个书签:
<?xml version="1.0" encoding="utf-8"?>
<bookmap>
<part>
<chapter/>
<chapter/>
<chapter/>
</part>
<part/>
<part/>
<part/>
<part/>
<appendix/>
</bookmap>
我想在模板中放置 xsl:if 命令,这些命令取决于元素是 part/chapter
还是 part
。
即我在模板 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 中,另一个图形只显示在 部分。
你需要做的是这样的:
<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 生成插件很有帮助,设置自定义封面图像,然后将您的代码与生成的插件的代码进行比较。
我是这样工作的:
<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>
我有这个书签:
<?xml version="1.0" encoding="utf-8"?>
<bookmap>
<part>
<chapter/>
<chapter/>
<chapter/>
</part>
<part/>
<part/>
<part/>
<part/>
<appendix/>
</bookmap>
我想在模板中放置 xsl:if 命令,这些命令取决于元素是 part/chapter
还是 part
。
即我在模板 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 中,另一个图形只显示在 部分。
你需要做的是这样的:
<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 生成插件很有帮助,设置自定义封面图像,然后将您的代码与生成的插件的代码进行比较。
我是这样工作的:
<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>