I need to convert the following XML to desired output-
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<entry>
<key>first_node/P_NODE</key>
<value>
<genericData>
<identifier>first_node/P_NODE</identifier>
<properties>
<entry>
<key>second_node</key>
<value>2</value>
</entry>
<entry>
<key>third_node/fourth_node/fifth_node</key>
<value>345</value>
</entry>
<entry>
<key>sixth_node/seventh_node</key>
<value>67</value>
</entry>
<entry>
<key>eigth_node</key>
<value>8</value>
</entry>
<entry>
<key>ninth_node</key>
<value>
<genericData>
<identifier>ninth_node</identifier>
<properties>
<entry>
<key>tenth_node</key>
<value>10</value>
</entry>
<entry>
<key>eleventh_node/twelveth_node</key>
<value>1112</value>
</entry>
</properties>
</genericData>
<genericData>
<identifier>ninth_node</identifier>
<properties>
<entry>
<key>x_node</key>
<value>10</value>
</entry>
<entry>
<key>y_node</key>
<value>1112</value>
</entry>
</properties>
</genericData>
</value>
</entry>
</properties>
</genericData>
</value>
</entry>
<entry>
<key>tirteenth_node</key>
<value>
<genericData>
<identifier>tirteenth_node</identifier>
<properties>
<entry>
<key>fourteenth_node</key>
<value>14</value>
</entry>
<entry>
<key>fifteenth_node/sixteenth_node</key>
<value>1516</value>
</entry>
</properties>
</genericData>
</value>
</entry>
<entry>
<key>seventeeth_node/eighteenth_node</key>
<value>1718</value>
</entry>
<entry>
<key>nineteenth_node/twenth_node</key>
<value>1920</value>
</entry>
<entry>
<key>twentyfirst_node</key>
<value>21</value>
</entry>
</properties>
Desired Output:
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<first_node>
<P_NODE>
<second_node>2</second_node>
<third_node>
<fourth_node>
<fifth_node>345</fifth_node>
</fourth_node>
</third_node>
<sixth_node>
<seventh_node>67</seventh_node>
</sixth_node>
<eigth_node>8</eigth_node>
<ninth_node>
<tenth_node>10</tenth_node>
<eleventh_node>
<twelveth_node>1112</twelveth_node>
</eleventh_node>
</ninth_node>
<ninth_node>
<x_node>10</x_node>
<y_node>1112</y_node>
</ninth_node>
</P_NODE>
</first_node>
<tirteenth_node>
<fourteenth_node>14</fourteenth_node>
<fifteenth_node>
<sixteenth_node>1516</sixteenth_node>
</fifteenth_node>
</tirteenth_node>
<seventeeth_node>
<eighteenth_node>1718</eighteenth_node>
</seventeeth_node>
<nineteenth_node>
<twenth_node>1920</twenth_node>
</nineteenth_node>
<twentyfirst_node>21</twentyfirst_node>
</properties>
Kindly let me know the XSLT which can be used to achieve the above.
I have used the code which is answered through the question "Escape backslash in XML and split as separate xml node using XSLT". However, when I use the same code for the above XML, it is printing the child elements inside parent but also printing as standalone elements. Note: The question has been amended to represent the actual problem statement.
Thank you.
You firstly need to add a second template matching
entry
nodes which hasgenericData
under it, as you will need to repeat the code for each such nodeYou also need to tweak the code that checks for descendant
entry
nodes, so that it only gets the first level ofentry
nodes, not all descendantsTry this XSLT: