这种转变
:
<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="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*">
<xsl:sort select="name()"/>
</xsl:apply-templates>
<xsl:apply-templates select="node()">
<xsl:sort select="name()"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
应用于此XML文档时
:
<t b="x" c="y" a="t">
<c/>
<b/>
<a/>
</t>
生成所需的排序输出
:
<t a="t" b="x" c="y">
<a></a>
<b></b>
<c></c>
</t>
:
-
不仅对元素进行排序,而且对属性进行排序
(后者依赖于实现,但可以与MSXML一起使用)。
-
,因为将XML文档转换为排序表示不是1:1映射。