2017-02-03 5 views
0

を並べ替え、私は彼らの親の下にいくつかの要素を移動し、属性「メッセージID」で注文したいXSLT 1.0:ここに移動親の下に要素とそれらを

はXML

<Root> 
<parent> 
<child/> 
<child2 messageid="8"/> 
<child/> 
<child2 messageid="5"/> 
<child/> 
<child2 messageid="7"/> 
</parent> 
</Root> 
ですここで

が欲しかったXML出力

<Root> 
<parent> 
<child/> 
<child/> 
<child/> 
<child2 messageid="5"/> 
<child2 messageid="7"/> 
<child2 messageid="8"/> 
</parent> 
</Root> 

である私は、XSLを使用する必要があると思う:コピーが、私はどのように行うのか分かりません。助けてくれてありがとうは、このような

+0

ものが一番下にする必要があります:parentノード上のわずかに変更されたアイデンティティーテンプレートを使用
は、仕事をするように見えますか?要素child2、またはmessageid属性を持つすべての要素?一番下のものだけをソートするか? – Lucero

+0

申し訳ありません。すべてのchild2要素は、一番下になければならず、messageidでソートする必要があります。 – CRT

答えて

0

何か作業をする必要があります:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:template match="parent"> 
    <xsl:copy> 
     <xsl:copy-of select="@*" /> 
     <xsl:apply-templates select="*[not(self::child2)]" /> 
     <xsl:apply-templates select="child2"> 
     <xsl:sort data-type="number" select="@messageid" /> 
     </xsl:apply-templates> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="*|node()"> 
    <xsl:copy> 
     <xsl:copy-of select="@*" /> 
     <xsl:apply-templates select="*|node()" /> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 
+0

ありがとうございました。これは、ソートでmode = numberを削除した場合にのみ有効です:) – CRT

+0

@CRT右の属性は 'data-type'と呼ばれるべきです。それがないと、テキストソートを行います。 「10」は「2」未満とみなされます。 – Lucero

+0

arf okですが、10よりも良いとは言えません.2よりも小さいです。これを修正する方法はありますか?データ型と呼ばれるべきことは何を意味しますか? – CRT

0

は、それも容易であろう。

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes" /> 

    <!-- slightly modified identity template --> 
    <xsl:template match="parent"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"> 
     <xsl:sort select="@messageid"/> 
     </xsl:apply-templates> 
    </xsl:copy> 
    </xsl:template> 

    <!-- identity template --> 
    <xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*" /> 
    </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 
関連する問題