2012-07-11 19 views
-1

我需要兩個節點MANHATTAN合併:如何合併具有「同一個父親」並具有精確「方法」序列的兩個節點(使用XSLT)?

,因爲我們的系統規則如下:

創建 A + MODIFY A」 仍然是一個「創建一個與合併後的屬性「

輸入文件:

<?xml version="1.0" encoding="UTF-8"?> 
<world> 
<COUNTRY id="USA" > 
    <STATE id="NEW JERSEY"> 
    <CITY id="NEW YORK" method="modify"> 


     <DISTRICT id="MANHATTAN" method="create"> 
      <attributes> 
       <population>99 </population> 
       <income> 10000</income> 
      </attributes> 
     </DISTRICT> 

     <DISTRICT id="MANHATTAN" method="modify"> 
      <attributes> 
       <temperature>78</temperature> 
       <income>15000</income> 
       <information>suburb of newyork</information> 
      </attributes> 
     </DISTRICT> 

    </CITY> 

    </STATE> 

預期輸出:

<?xml version="1.0" encoding="UTF-8"?> 
<world> 
<COUNTRY id="USA" > 
    <STATE id="NEW JERSEY"> 
    <CITY id="NEW YORK" method="modify"> 

     <DISTRICT id="MANHATTAN" method="create"> 
      <attributes> 
       <population>99 </population> 
       <temperature>78</temperature> 
       <income>15000</income> 
       <information>suburb of newyork</information> 
      </attributes> 
     </DISTRICT> 

    </CITY> 
</STATE> 
</COUNTRY> 
</world> 

請幫幫忙,我剛開始XSLT和Perl中做或Python將需要數個小時。

+0

總會有兩個節點嗎? – sreehari 2012-07-11 06:17:41

+0

是的,你猜對了。規則是它總是1 CREATE + 1 MODIFY被轉換成1 CREATE – laurentngu 2012-07-11 06:45:34

回答

相關問題