2017-03-18 6 views
0

私はこれに多くの時間を費やしており、可能な解決策に手を差し伸べると思っていました。これはテスト用に単純化したXMLです。XSLT-1.0:子ノードグループをソートしてその階層を保持する方法

<Data> 
    <Superbill> 
     <Attributes> 
     </Attributes> 
     <Children> 
      <ListByMatter> 
       <ListByMatter> 
        <Children> 
         <ListofProfDetailTime> 
          <ListofProfDetailTime> 
           <Attributes> 
            <id>1</id> 
            <Date>2011-02-11</Date> 
           </Attributes> 
          </ListofProfDetailTime> 
          <ListofProfDetailTime> 
           <Attributes> 
            <id>2</id> 
            <Date>2010-11-02</Date> 
           </Attributes> 
          </ListofProfDetailTime> 
          <ListofProfDetailTime> 
           <Attributes> 
            <id>11</id> 
            <Date>2015-09-12</Date> 
           </Attributes> 
          </ListofProfDetailTime> 
          <ListofProfDetailTime> 
           <Attributes> 
            <id>1</id> 
            <Date>2013-11-12</Date> 
           </Attributes> 
          </ListofProfDetailTime> 
         </ListofProfDetailTime> 
        </Children> 
       </ListByMatter> 
      </ListByMatter> 
     </Children> 
    </Superbill> 
</Data> 

私はこれを私の変換のために書いていますが、元の階層になっている順序付けられた結果から古いノードを置き換える方法を理解できません。私はこのウェブサイトhttp://xsltransform.net/を使って素早く変更を行っていますが、私は何かシンプルが欠けていると思っています。あるいは、予想以上に複雑になるでしょう。私はちょうど最近自分でこれを学ぶことを始め、いくつかのガイダンスが必要です。

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="/"> 
     <xsl:copy> 
     <xsl:apply-templates select="//ListofProfDetailTime/ListofProfDetailTime"> 
      <xsl:sort select="Attributes/Date" order="ascending"/> 
     </xsl:apply-templates> 
     </xsl:copy> 
    </xsl:template> 

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

</xsl:transform> 
+0

希望の出力XMLはどのように見えますか? – zx485

答えて

1

ご質問が正確であるかどうか不明です。

<xsl:template match="/"> 
     <xsl:copy> 
     <xsl:apply-templates select="//ListofProfDetailTime/ListofProfDetailTime"> 
      <xsl:sort select="Attributes/Date" order="ascending"/> 
     </xsl:apply-templates> 
     </xsl:copy> 
    </xsl:template> 

:あなたは、元の階層を維持しようとしている、とだけ内側のListofProfDetailTime要素のソート順を変更している場合は、これを変更

<xsl:template match="Children/ListofProfDetailTime"> 
    <xsl:copy> 
     <xsl:apply-templates select="ListofProfDetailTime"> 
      <xsl:sort select="Attributes/Date" order="ascending"/> 
     </xsl:apply-templates> 
    </xsl:copy> 
</xsl:template> 

あなたは今それを持っている方法は、あなたのテンプレートは/ルートノードに一致し、そこからはListofProfDetailTime子孫に直接テンプレートが適用され、中間レベルは決して処理されません。

+0

それは私が必要としていた正確な結果であり、それを説明することに感謝しています。 –

関連する問題