【发布时间】:2020-02-14 05:57:41
【问题描述】:
我的输入 xml 如下所示:
<sect1>
<title>Intro</title>
<sect2>
<title>Purpose</title>
<sect3>
<title>Scope</title>
</sect3>
</sect2>
<sect2>
<title>Take</title>
<table><title>Table 1</title></table>
</sect2>
</sect1>
我已经为上面的 xml 创建了 XSL:
<xsl:variable name="xmlpath" select="/files/path"/>
<xsl:variable name="rootLangLoc" select="/files/@xml:lang"/>
<xsl:variable name="newline"><xsl:text> </xsl:text></xsl:variable>
<xsl:variable name="linebreak"><xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:text>Top Heading,Sub Heading</xsl:text>
<xsl:value-of select="$linebreak"/>
<xsl:for-each select="files/file">
<xsl:variable name="FullName" select="concat($xmlpath, ., $rootLangLoc, '.xml')"/>
<xsl:apply-templates select="document($FullName)" mode="csvprocess"/>
</xsl:for-each>
<xsl:for-each select="/sect1/title">
<xsl:apply-templates select="."/>
<xsl:for-each select="/sect1/sect2/title">
<xsl:value-of select="$newline"/>
<xsl:text>,</xsl:text>
<xsl:apply-templates select="/sect1/sect2/title"/>
<xsl:for-each select="/sect1/sect2/sect3/title">
<xsl:value-of select="$newline"/>
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
<xsl:apply-templates select="/sect1/sect2/sect3/title"/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
我得到的 CSV 输出如下:
Intro
,Purpose
,Take
,,Scope
例外的输出是:
Intro
,Purpose
,,Scope
,Take
我希望所有部分的标题都按照输入 xml 的正确顺序排列。我得到的输出类似于第 1 节标题的第一个和第 2 节标题的下一个。
【问题讨论】: