XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[*][deep-equal(.,preceding::*[name()=current()/name()][@id=current()/@id][1])]"/>
</xsl:stylesheet>
私の入力に適用されたとき:
<myroot>
<nodeA id="a">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"> <!-- second consecutive create, we will remove this -->
<somechild>a</somechild>
</item1>
<item1 id="0" method="create"> <!-- third consecutive create, BUT children have different value , so we don't remove this -->
<somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
<item1 id="0" method="change"> <!-- second consecutive create, we will remove this -->
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
</myroot>
正しい出力を教えてください:
<myroot>
<nodeA id="a">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"> <!-- third consecutive create, BUT children have different value , so we don't remove this -->
<somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
</myroot>
*しかし、問題は、別のnodeA
ノードid
がある場合、これら2つのノードを1つとして扱うことです*
2 番目の入力例:
<myroot>
<nodeA id="a">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"> <!-- second consecutive create, we will remove this -->
<somechild>a</somechild>
</item1>
<item1 id="0" method="create"> <!-- third consecutive create, BUT children have different value , so we don't remove this -->
<somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
<item1 id="0" method="change"> <!-- second consecutive create, we will remove this -->
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
<nodeA id="b">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"> <!-- second consecutive create, we will remove this -->
<somechild>a</somechild>
</item1>
<item1 id="0" method="create"> <!-- third consecutive create, BUT children have different value , so we don't remove this -->
<somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
<item1 id="0" method="change"> <!-- second consecutive create, we will remove this -->
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
</myroot>
私の出力:
<myroot>
<nodeA id="a">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"><!-- third consecutive create, BUT children have different value , so we don't remove this --><somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
<nodeA id="b">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"><!-- third consecutive create, BUT children have different value , so we don't remove this --><somechild>bbb</somechild>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
</myroot>
期待される出力の場所:
<myroot>
<nodeA id="a">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"> <!-- third consecutive create, BUT children have different value , so we don't remove this -->
<somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
<nodeA id="b">
<section id="i">
<item1 id="0" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="create">
<otherchild>a</otherchild>
</item1>
</section>
<section id="i">
<item1 id="0" method="create"> <!-- third consecutive create, BUT children have different value , so we don't remove this -->
<somechild>bbb</somechild>
</item1>
<item1 id="3" method="create">
<other>xx</other>
</item1>
<item1 id="0" method="change">
<otherchild>a</otherchild>
</item1>
</section>
</nodeA>
</myroot>
2 つ以上のノードの親などに対して機能させるには、XSLT ファイルに何を追加する必要がありますnodeA
か。nodeB
successive duplicate
目的は、同じ要素名item1
item2
など、同じid
と同じでノードを削除することですmethod
。same element name
正確な、same id
、same method
およびを含む他のノードが続く XML ノードは、same children
重複していると見なされます。比較されている 2 つのノードが同じ「nodeA」レベルのノードを共有していない場合、それらは削除される重複と見なされるべきではありません。
ありがとうジョン