如何保存xml元素';使用xslt设置数据位置

如何保存xml元素';使用xslt设置数据位置,xml,xslt-2.0,Xml,Xslt 2.0,我们正在转换一些类似于以下xml的内容: <collection> <availableLocation>NY</availableLocation> <cd> Fight for your mind </cd> <cd> Electric Ladyland </cd> <availableLocation>NJ</

我们正在转换一些类似于以下xml的内容:

<collection>
    <availableLocation>NY</availableLocation>
    <cd>
        Fight for your mind
    </cd>
    <cd>
        Electric Ladyland
    </cd>
    <availableLocation>NJ</availableLocation>
</collection>
我们希望保持xml中的顺序。我们希望输出如下:

NY

Fight for your mind 
Electric Ladyland 

NJ
有没有办法做到这一点?请评论/建议

我通过做这些改变找到了解决办法


请告诉我们是否有更好的解决方案

提前感谢


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

最简单的解决方案之一甚至不需要明确的


或者更好,只需执行
(无需选择)。为什么这么难?好问题,+1。请参阅我的答案,以获得一个完整而简单、简短且简单的解决方案,它甚至不需要一个
:)
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: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>
<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