我有一层有几层筑巢的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选择标题?
答案 0 :(得分:2)
使用document()函数和apply-templates导航层次结构。这应该适合你:
<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>