【问题标题】:how to merge two nodes having "the same father" and having a precise "method" sequence (using XSLT)?如何合并具有“相同父亲”和具有精确“方法”序列的两个节点(使用 XSLT)?
【发布时间】:2012-07-11 05:17:53
【问题描述】:

我需要合并两个节点MANHATTAN:

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

CREATE A + MODIFY A”仍然是“CREATE A with the combined attributes”

输入文件:

<?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 CREATE + 1 MODIFY 转换成 1 CREATE

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


【解决方案1】:

根据how to merge two nodes having "the same father", the same method and the same id=0 (using XSLT)?的类似问题调整解决方案

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-29
    • 2016-09-04
    • 1970-01-01
    • 2021-12-29
    相关资源
    最近更新 更多