如何合并具有“相同父亲”并具有精确“方法”序列的两个节点(使用XSLT)?

时间:2012-07-11 05:17:53

标签: xml xslt xslt-1.0 xslt-2.0 xmlnode

我需要合并两个节点MANHATTAN:

因为我们的系统规则如下:

创建 A + MODIFY A”仍然是“创建 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中完成它需要几个小时。

1 个答案:

答案 0 :(得分:0)

how to merge two nodes having "the same father", the same method and the same id=0 (using XSLT)?

处修改类似问题的解决方案

阅读解决方案以了解分组的工作原理,然后相应地更改分组键。