I have an XML file from which I have to extract a specific part based on the id attribute.
Input XML
<root>
<item id="id_1" state="closed">
<content>
<name>Details</name>
</content>
<item state="closed" id="id_1_1">
<content>
<name title="Name">Identity</name>
</content>
<item id="id_1_1_1" state="closed">
<content>
<name title="Name">Name</name>
</content>
<item id="id_1_1_1_1">
<content>
<name title="First Name">First Name</name>
</content>
</item>
<item id="id_1_1_1_2">
<content>
<name title="Last Name">Last Name</name>
</content>
</item>
</item>
<item id="id_1_1_2" state="closed">
<content>
<name title="Address">Address</name>
</content>
<item id="id_1_1_2_1">
<content>
<name title="Address Line 1">Line 1</name>
</content>
</item>
<item id="id_1_1_2_2">
<content>
<name title="Address Line 2">Line 2</name>
</content>
</item>
<item id="id_1_1_2_3">
<content>
<name title="City">City</name>
</content>
</item>
</item>
</item>
<item>
</root>
If I gave id_1_1 as input my output xml should be as below
Output
<item id="id_1_1_1" state="closed">
<content>
<name title="Name">Name</name>
</content>
</item>
<item id="id_1_1_2" state="closed">
<content>
<name title="Address">Address</name>
</content>
</item>
The output should take the items immediate below the selected node(of input id), and not any depth further.
This transformation:
when applied on the provided XML (slightly corrected to be made well-formed!):
produces the wanted, correct result: