我有一个包含以下标记的XML文件合并与整合节点含量值
<xml>
<content relationship="regula">
**<source attribute1="RSC1985s5c1" attribute2="6(17)"/>**
<target attribute1="LRC1985s5c1" attribute1="6(17)1"/>
</content>
<content relationship="translation-of">
**<source attribute1="RSC1985s5c1" attribute2="6(17)"/>**
<target attribute1="LRC1985s5c4" attribute2="6(17)1"/>
</content>
<content relationship="translation-of">
**<source attribute1="RSC1985s5c2" attribute2="7(17)"/>**
<target attribute1="LRC1985s5c2" attribute2="7(17)"/>
</content>
<content relationship="translation-of">
**<source attribute1="RSC1985s5c1" attribute2="6(17)"/>**
<target attribute1="LRC1985s5c6" attribute2="6(17)2"/>
</content>
</xml>
什么,我要的是节点的内容合并到一个新的节点,如果ATTRIBUTE1和attrbite2值的源节点是相等的。所以输出应该像
<xml>
<transformed relationship="merged">
<source attribute1="RSC1985s5c1" attribute2="6(17)"/>
<target attribute1="LRC1985s5c1" attribute2="6(17)1"/>
<target attribute1="LRC1985s5c4" attribute2="6(17)1"/>
<target attribute1="LRC1985s5c6" attribute2="6(17)2"/>
</transformed>
<transformed relationship="non-merged">
<source attribute1="RSC1985s5c2" attribute2="7(17)"/>
<target attribute1="LRC1985s5c2" attribute2="7(17)"/>
</transformed>
</xml>
所以第一个两个节点具有彼此相等源ATTRIBUTE1和attribute2值,这就是为什么我有将它们组合起来作为一个新的节点。源中的第三个节点与其他为什么我分开输出的节点不匹配。我尝试使用foreach循环,但无法得到适当的解决方法。感谢您的帮助,如果我们可以通过使用模板匹配来实现。
具有子节点“源”的相同属性的任何内容节点应该组合在一起,而不管它们的位置如何。的关系将得到改变为合并后的人与非合并项目“合并”这将是“非合并”
@_atif:任何两个“内容”节点与“共同”儿童合并?是否只有两个相邻的“内容”节点要合并?如果两个以上的“内容”节点具有“共同”元素会怎样? “关系”属性是否应该因合并而丢失?这个问题中有太多事情不清楚。请编辑并提供缺少的信息。 –
任何具有相同属性的子节点“源”的内容节点都应该组合在一起,无论它们的位置如何。对于合并后的关系将变为“合并”,非合并后的项目将变为“未合并” – atif
@_atif:嗯,在评论中这是很好的说法,但它属于问题 - 请编辑您的问题并在那里提供这些信息。此外,你没有回复我的问题什么应该是预期的输出id多于两个节点将被合并 - 请在你的问题中提供这样的例子。我绝对不愿意猜测你可能没有想过的事情...... –