我正在使用以下 XSLT,但排序后节点的顺序对我来说有点问题,因为它们与输入的顺序不同。
enter code here
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="Types">
<xsl:sort select="Type1"/>
</xsl:apply-templates>
<xsl:apply-templates select="SecondTypes">
<xsl:sort select="Type1"/>
</xsl:apply-templates>
<xsl:apply-templates select="ServiceOption">
<xsl:sort select="Issue"/>
</xsl:apply-templates>
<xsl:apply-templates select="ServiceConcession">
<xsl:sort select="Concession" data-type="number"/>
</xsl:apply-templates>
<xsl:apply-templates select="node()[not(self::Types|self::SecondTypes|self::ServiceOption|self::ServiceConcession)]|@*"/>
</xsl:copy>
</xsl:template>
最佳答案
只需修改身份转换,以便排序仅应用于所需的节点:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="Types">
<xsl:sort select="Type1"/>
</xsl:apply-templates>
<xsl:apply-templates select="node()[not(self::Types)]|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
关于xml - XSL 仅在一个节点上排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6685062/