2016-06-12 2 views
0

私は分割ノードは必ずしもソートされていないこの入力に XML文書を別の文書に正常に変換できません。

<root> 
    <row>  
     <guestid>G1</guestid> 
     <splits> 

      <split> 
       <begin_date>2015-03-01</begin_date> 
       <end_date>2016-06-30</end_date> 

       <apples>A01</apples> 
       <oranges>BB01</oranges> 
       <percent>60</percent> 
      </split> 

      <split> 
       <apples>A02</apples> 
       <oranges>BB02</oranges> 
       <percent>40</percent> 
      </split> 

     </splits> 
    <splits> 
    <!-- No gap from previous. Starts the next day. --> 
     <split> 
      <begin_date>2015-07-01</begin_date> 
      <end_date>2015-09-30</end_date> 
      <apples>A55</apples> 
      <oranges>BB55</oranges> 
      <percent>75</percent> 
     </split> 

     <split> 
      <begin_date>2015-07-01</begin_date> 
      <end_date>2015-09-30</end_date> 
      <apples>A100</apples> 
      <oranges>BB100</oranges> 
      <percent>25</percent> 
     </split> 
    </splits> 

    <splits> 
     <!-- There is a gap.(between 2015-10-01 and 2016-01-31 This will be filled up with defaut splits. --> 
     <split> 
      <begin_date>2016-02-01</begin_date> 
      <end_date>2016-02-29</end_date> 
      <apples>A777</apples> 
      <oranges>BB777</oranges> 
      <percent>85</percent> 
     </split> 

     <split> 
      <begin_date>2016-02-01</begin_date> 
      <end_date>2016-01-31</end_date> 
      <apples>A200</apples> 
      <oranges>BB200</oranges> 
      <percent>15</percent> 
     </split> 
    </splits> 

    <splits> 
     <!-- There is a gap.(between 2015-10-01 and 2016-01-31 This will be filled up with defaut splits. --> 
     <split> 
      <begin_date>2016-04-01</begin_date> 
      <end_date>2016-04-30</end_date> 
      <apples>A777</apples> 
      <oranges>BB777</oranges> 
      <percent>85</percent> 
     </split> 

     <split> 
      <begin_date>2016-04-01</begin_date> 
      <end_date>2016-04-30</end_date> 
      <apples>A200</apples> 
      <oranges>BB200</oranges> 
      <percent>15</percent> 
     </split> 
    </splits> 



    <default_splits> 

     <!-- no percentage. Will always be 100 percent. Never split. --> 
     <default>> 
      <begin_date>2015-01-01</begin_date> 
      <apples>AD1111</apples> 
      <oranges>BB1111</oranges> 
     </default> 

     <default> 
      <begin_date>2015-07-01</begin_date> 
      <apples>A2222</apples> 
      <oranges>BB2222</oranges> 
     </default> 

     <default> 
      <begin_date>2015-11-01</begin_date> 
      <apples>A8888</apples> 
      <oranges>BB8888</oranges> 

     </default> 
    </default_splits>   

</row> 

</root> 

を取るしようとしています。ソースxmlは読み込みごとに事前ソートされています。最終的な結果は次のようになります。 しかし、分割ノード内の掘り出し日付と終了日は同じであると予想されます。次のように予想

最終的な結果は次のとおりです。

<?xml version="1.0" encoding="UTF-8"?> 
<!--Output XML --> 

<root> 
    <row>  
     <guestid>G1</guestid> 
     <splits> 
      <!-- Reg --> 
     <split> 
      <begin_date>2015-03-01</begin_date> 
      <end_date>2016-06-30</end_date> 

      <apples>A01</apples> 
      <oranges>BB01</oranges> 
      <percent>60</percent> 
     </split> 

     <split> 
      <apples>A02</apples> 
      <oranges>BB02</oranges> 
      <percent>40</percent> 
     </split> 

    </splits> 
    <splits> 
     <!-- Reg no gap between prior split and this split. --> 
     <split> 
      <begin_date>2015-07-01</begin_date> 
      <end_date>2015-09-30</end_date> 
      <apples>A55</apples> 
      <oranges>BB55</oranges> 
      <percent>75</percent> 
     </split> 

     <split> 
      <begin_date>2015-07-01</begin_date> 
      <end_date>2015-09-30</end_date> 
      <apples>A100</apples> 
      <oranges>BB100</oranges> 
      <percent>25</percent> 
     </split> 
    </splits> 
    <!-- aded from default to cover the gap.--> 
    <splits> 
     <!-- based on default--> 
     <!-- based on default --> 
     <split> 

      <begin_date>2015-10-01</begin_date> 
      <end_date>2015-10-31</end_date> 
      <apples>AD1111</apples> 
      <oranges>BB1111</oranges>> 
      <percent>100</percent> 

     </split> 
    </splits> 

    <!-- added from the second default split. But ended before start of regular split. --> 
    <splits> 
     <!-- Default --> 
     <split> 

      <begin_date>2015-11-01</begin_date> 
      <end_date>2016-01-31</end_date6 
      <apples>A8888</apples> 
      <oranges>BB8888</oranges> 
      <percent>100</percent> 

     </split> 
    </splits> 

    <splits> 
     <!-- Reg --> 
     <split> 
      <begin_date>2016-02-01</begin_date> 
      <end_date>2016-02-29</end_date> 
      <apples>A777</apples> 
      <oranges>BB777</oranges> 
      <percent>85</percent> 
     </split> 

     <split> 
      <begin_date>2016-02-01</begin_date> 
      <end_date>2016-02-29</end_date> 
      <apples>A200</apples> 
      <oranges>BB200</oranges> 
      <percent>15</percent> 
     </split> 
    </splits> 

    <splits> 
     <!-- Gap Filled up --> 
     <!-- based on default --> 
     <split> 
      <begin_date>2016-03-01</begin_date> 
      <end_date>2016-03-31</end_date> 
      <apples>A8888</apples> 
      <oranges>BB8888</oranges> 
      <percent>100</percent> 
     </split> 
    </splits> 


<splits> 
    <!-- Reg -->  
     <split> 
      <begin_date>2016-04-01</begin_date> 
      <end_date>2016-04-30</end_date> 
      <apples>A777</apples> 
      <oranges>BB777</oranges> 
      <percent>85</percent> 
     </split> 

     <split> 
      <begin_date>22016-04-01</begin_date> 
      <end_date>2016-04-30</end_date> 
      <apples>A200</apples> 
      <oranges>BB200</oranges> 
      <percent>15</percent> 
     </split> 
    </splits> 


    <!--added as there is an end date on last row. default values active to be used--> 


    <splits> 
     <!-- from default --> 
     <split> 
       <begin_date>2016-05-01</begin_date> 
      <apples>A8888</apples> 
      <oranges>BB8888</oranges> 
      <percent>100</percent>    
     </split> 
    </splits> 


</row> 

私は次のように構築しTRED。しかし、エラー状態のために立ち往生しています。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      version="2.0"> 
<xsl:output method="xml" indent="yes"/> 


<xsl:template match="/root/row"> 
    <row> 
    <xsl:for-each select="splits"> 
     <xsl:sort select="xs:date(split/begin_date[1])" order="descending"/> 

     <xsl:for-each select="."> 
      <newsplit> 
       <begin_date><xsl:value-of select="begin_date" />    </begin_date> 
       <end_date><xsl:value-of select="end_date" /></end_date> 
       <apples><xsl:value-of select= "apples" /></apples> 
       <oranges><xsl:value-of select= "oranges" /></oranges> 
       <pct><xsl:value-of select= "percent" /></pct> 
      </newsplit> 
     </xsl:for-each>  

    </xsl:for-each> 

    </row> 
</xsl:template> 

</xsl:stylesheet> 

発生したエラーがある - 複数の項目の配列は式「としてキャスト」の値として許可されていない私は遠くからまだ午前知っている[22]

これを完了する。しかし、この時点で立ち往生しています。ご意見とご協力をいただければ幸いです。おかげさまで

+0

あなたは 'xsl:perform-sort'(https://www.w3.org/TR/xslt20/#creating-sorted-sequence)を使う必要があると思います。 – potame

+0

ありがとうございます。 – StillStumbling

答えて

0

splitsbegin_dateという2つの子split要素があるとすぐに、式xs:date(split/begin_date[1])はそのエラーを示します。これを避けるにはxs:date((split/begin_date)[1])を使用してください。残りの問題を理解することは実際にはできていないので、その修正があなたの変換問題を解決するのに役立つかどうかは分かりません。

+0

Martinさん、ありがとうございました。それはうまくいかなかった。 – StillStumbling

+0

これはxs:date(split [1]/begin_date)で動作しました。 – StillStumbling

関連する問題