If I have this input file in xml:
<root>
<node id="N1">
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Orange</color>
<year>2000</year>
</attribute>
</orange>
</fruit>
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Orange</color>
<condition>good</condition>
</attribute>
</orange>
</fruit>
</node>
</root>
and here is the expected output:
<root>
<node id="N1">
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Orange</color>
<year>2000</year>
<condition>good</condition>
</attribute>
</orange>
</fruit>
<fruit id="1">
</fruit>
</node>
</root>
How to simplify between two sibling:
- check if the parent is the same (fruit id=1)
- check if the node id and action is the same (orange id=x action=create)
- if the child element is already defined previously and the value is the same (color-orange) , we remove it.
- If the child element of the second sibling is not defined perviously we add that second node to the first node. (condition-good)
- If the node is already defined previously but different value (say color-red), we leave the node as it is.
Another scenario: input2:
<root>
<node id="N1">
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Orange</color>
</attribute>
</orange>
</fruit>
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Red</color>
<condition>good</condition>
</attribute>
</orange>
</fruit>
</node>
</root>
Expected ouput:
<root>
<node id="N1">
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Orange</color>
<condition>good</condition>
</attribute>
</orange>
</fruit>
<fruit id="1">
<orange id="x" action="create">
<attribute>
<color>Red</color>
</attribute>
</orange>
</fruit>
</node>
</root>
Another scenario:
<root>
<nodeA id="A">
<fruit id="1">
<orange id="x" action="delete" /> <!-- no attributes here -->
</fruit>
<fruit id="1">
<orange id="x" action="delete"/>
<orange id="y" action="delete" />
</fruit>
</nodeA>
</root>
Expected output:
<root>
<nodeA id="A">
<fruit id="1">
<orange id="x" action="delete" />
</fruit>
<fruit id="1">
<orange id="y" action="delete" />
</fruit>
</nodeA>
</root>
I hope the example give the clear idea and please help me with the transformation file. Thanks.
John
condition
moves up to the first declaration of thecreate orange
? I would get it if you merged it so that it sayscolor Red
andcondition good
and have it only once, basically a superset with the most "recent" values taking precedence over previously defined. Am I missing something? - Pavel Veller