当上下文是主题或图像时,如何获取DITA图书地图中mainbooktitle元素的值?

时间:2019-04-04 11:05:30

标签: dita

在DITA主题中处理图像时,我想包括书名或地图名。那可能吗?如何在图像的XSLT上下文中访问书名值?

1 个答案:

答案 0 :(得分:0)

  

如何在图像的XSLT上下文中访问书名值?

假设您正在使用DITA-OT HTML5转换进行HTML发布,则可以通过实现Customizing DITA Open Toolkit中所述的三个扩展点来从主题模板访问地图信息。

  • dita.conductor.html5.param
  • dita.conductor.html5.toc.param
  • dita.xsl.html5

名为“ com.acme.html5.param”和“ com.acme.html5”的示例插件结构:

<?xml version="1.0" encoding="UTF-8"?>
<plugin id="com.acme.extend.html5.param">
    <feature extension="dita.conductor.html5.param" file="buildHtml5Param.xml"/>
    <feature extension="dita.conductor.html5.toc.param" file="buildHtml5Param.xml"/>
</plugin>

[com.acme.html5.param / plugin.xml]

<?xml version="1.0" encoding="UTF-8"?>
<params xmlns:if="ant:if">
    <param name="input.map.url" expression="${html5.map.url}" if:set="html5.map.url"/>
</params>

[com.acme.html5.param / buildHtml5Param.xml]

<?xml version="1.0" encoding="UTF-8"?>
<plugin id="com.acme.html5">
    <feature extension="dita.xsl.html5" file="xsl/dita2html5_acme_custom.xsl"/>
</plugin>

[com.acme.html5 / plugin.xml]

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
    exclude-result-prefixes="xs dita-ot"
    version="2.0">

    <!-- map URL -->
    <xsl:param name="input.map.url" as="xs:anyURI" required="yes"/>

    <!-- map document -->
    <xsl:variable name="mapDoc" as="document-node()" select="doc($input.map.url)"/>

    <!-- map title -->
    <xsl:variable name="title" as="xs:string">
        <xsl:variable name="titleTexts" as="xs:string*">
            <xsl:choose>
                <xsl:when test="$mapDoc/*[contains(@class,' bookmap/bookmap ')]">
                    <xsl:apply-templates select="$mapDoc/*[contains(@class, ' bookmap/bookmap ')]/*[contains(@class, ' bookmap/booktitle ')]/*[contains(@class, ' bookmap/mainbooktitle ')]" mode="dita-ot:text-only"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="$mapDoc/*[contains(@class, ' map/map ')]/*[contains(@class, ' topic/title ')]" mode="dita-ot:text-only"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:sequence select="string-join($titleTexts,'')"/>
    </xsl:variable>

    <!-- override image template -->
    <xsl:template match="*[contains(@class, ' topic/image ')]" name="topic.image">
        <!-- snip! -->
        ...
        <!-- customization here! -->
        <div>Map: <xsl:value-of select="$title"/></div>
    </xsl:template>

</xsl:stylesheet>

[com.acme.html5 / xsl / dita2html5_acme_custom.xsl]

dita-ot-3.3/docsrc/samples/sequence.ditamap

通过添加以上插件,构建<map> <title>Working in the garage</title> <topicref href="tasks/changingtheoil.xml" type="task"/> ... <topicref href="tasks/washingthecar.xml" type="task"/> ... </map> 时可以获得以下示例结果。

[dita-ot-3.3 / docsrc / samples / sequence.ditamap]

{{1}}

[dita-ot-3.3 / docsrc / samples / tasks / washingthecar.xml]

washingthecar.html