1

我有一个带有多层嵌套的 ditamap。它看起来像这样:

<map>
    <title>This is the document title</title>
    <mapref href="section1.ditamap" format="ditamap"/>
    <mapref href="section2.ditamap" format="ditamap"/>
</map>

section1.ditampa 看起来像这样:

<map>
    <topicref href="section1.dita">
        <topicref href="subsection1.dita">
            <topicref href="subsubsection1.dita"/>
            <topicref href="subsubsection2.dita"/>
            <topicref href="subsubsection3.dita"/>
        </topicref>
    </topicref>
</map>

section1.dita 看起来像这样:

<topic>
    <title>This is the title for section 1</title>
</topic>

subsection1.dita 看起来像这样:

<topic>
    <title>This is the title for subsection 1</title>
</topic>

如何在转换中选择 section1 和 subsection1 的标题?

4

1 回答 1

2

使用 document() 函数和应用模板来导航层次结构。这应该适合你:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">

    <xsl:template match="/map">
        <xsl:apply-templates select="mapref"/>
    </xsl:template>
    <xsl:template match="mapref">
        <xsl:apply-templates select="document(@href)/map/topicref"/>
    </xsl:template>    
    <xsl:template match="topicref">
        <xsl:apply-templates select="document(@href)/topic"/>
        <xsl:apply-templates select="topicref"/>
    </xsl:template>    
    <xsl:template match="topic">
        <xsl:message>
            <xsl:value-of select="title"/>
        </xsl:message>
    </xsl:template>
    </xsl:stylesheet>
于 2013-09-23T03:59:28.743 回答