如何使用xslt保留xml元素的数据位置

|| 我们正在转换类似以下xml的内容:
<collection>
    <availableLocation>NY</availableLocation>
    <cd>
        Fight for your mind
    </cd>
    <cd>
        Electric Ladyland
    </cd>
    <availableLocation>NJ</availableLocation>
</collection>
使用以下xslt
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:output method=\"html\"/>
<xsl:template match=\"/\">
    <html>
        <body>

                 <xsl:apply-templates select=\"collection/availableLocation\"/>
                <xsl:apply-templates select=\"collection/cd\"/>

        </body>
    </html>
</xsl:template>
<xsl:template match=\"availableLocation\">
    <h3>
        <xsl:value-of select=\".\"/>
    </h3>
</xsl:template>
<xsl:template match=\"cd\">
    <xsl:value-of select=\".\"/><br/>
</xsl:template>


</xsl:stylesheet>
输出为:
NY

NJ

Fight for your mind 
Electric Ladyland 
我们希望保留xml中的顺序。我们希望输出如下:
NY

Fight for your mind 
Electric Ladyland 

NJ
有什么办法吗?请评论/建议。 我通过做这些改变找到了解决方案
            <xsl:for-each select=\"collection\">

                <xsl:apply-templates select=\".\"/>

                </xsl:for-each>

    </body>
请让我们知道是否有更好的解决方案。 提前致谢     
已邀请:
        
<xsl:apply-templates select=\"collection/availableLocation|collection/cd\"/>
    
        最简单的解决方案之一甚至不需要明确的
<xsl:apply-templates>
<xsl:stylesheet version=\"1.0\"
 xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
 <xsl:output omit-xml-declaration=\"yes\" indent=\"yes\"/>
 <xsl:strip-space elements=\"*\"/>

 <xsl:template match=\"text()\">
  <xsl:value-of select=\"normalize-space()\"/>
  <xsl:text>&#xA;</xsl:text>
 </xsl:template>
</xsl:stylesheet>
当应用于提供的XML文档时:
<collection>
    <availableLocation>NY</availableLocation>
    <cd>
      Fight for your mind
    </cd>
    <cd>
      Electric Ladyland
    </cd>
    <availableLocation>NJ</availableLocation>
</collection>
所需的正确结果产生了:
NY
Fight for your mind
Electric Ladyland
NJ
    

要回复问题请先登录注册