输入文件:
<root>
<sector>
<nodeA id="a">
<section id="i">
<item1 id="1" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="delete" />
</section>
</nodeA>
<nodeA id="b">
<cell id="ii">
<item2 id="2" method="create">
<otherchild>a</otherchild>
</item2>
</cell>
<cell id="ii">
<item2 id="2" method="delete" />
</cell>
</nodeA>
<nodeB id="i">
<cell id="ii">
<item3 id="1" method="create">
<child>b</child>
</item3>
</cell>
<cell id="ii">
<item3 id="1" method="delete" />
<item3 id="1" method="create">
<otherchild>a</otherchild>
</item3>
</cell>
</nodeB>
</sector>
</root>
预期输出:
<root>
<sector>
<nodeA id="a">
<section id="i">
</section>
</nodeA>
<nodeA id="b">
<cell id="ii">
</cell>
<cell id="ii">
</cell>
</nodeA>
<nodeB id="i">
<cell id="ii">
<item3 id="1" method="create"> <!-- this is not eliminated as it violates the rule by having create followed by delete and followed by create again -->
<child>b</child>
</item3>
</cell>
<cell id="ii">
<item3 id="1" method="delete" />
<item3 id="1" method="create">
<otherchild>a</otherchild>
</item3>
</cell>
</nodeB>
</sector>
</root>
我需要使用此规则消除 xml 中的节点:
- 一个节点
method="create"
跟随 一个节点method="delete"
将被淘汰 - 该场景可以发生在一个父级中,也可以在两个父级中传播,只要它具有相同的元素名称和 id
<cell id="ii">
如何使用 XSLT 1.0 或 2.0 进行这种转换?
谢谢你。