xml - XSL 仅在一个节点上排序

标签 xml xslt

我正在使用以下 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/

相关文章:

xslt - 如何在 xslt 中设置事件按钮?

xslt - XSL 替换字符 ( )

xml - 是否可以使用 XSLT 翻转和旋转文本?

c# - 如何将 XmlNodeList 转换为 NodeSet 以在 XSLT 中使用?

xml - 如何将 Xml 文件转换为文本文件

xml - 使用 XSLT 合并多个 XML 文件并执行一些数学函数

java - 如何将图像标题添加到我的抽屉导航布局中

java - 自定义 ListView 适配器空对象引用

java - 以编程方式在 Java/Android 中进行 Saxon XSLT 转换

c# - 如何在 C# 中向从数据集 Writexml 生成的 XML 添加额外信息?