开发者

XSL Sort only on one node

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜