开发者

XSL Sort only on one node

开发者 https://www.devze.com 2023-03-20 07:08 出处:网络
I\'m using the following XSLT,but the order of nodes after sorting is a bit problem for me as they are not following the same order as of the input.

I'm using the following XSLT,but the order of nodes after sorting is a bit problem for me as they are not following the same order as of the input.

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:ap开发者_StackOverflow中文版ply-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>


Just modify the identity transformation so that sort is applied to the wanted nodes only:

<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> 
0

精彩评论

暂无评论...
验证码 换一张
取 消