I have a sample XML message which contains multiple parent node. The requirement is something like if the two parent node are same, merge the child node.
Sample Input Message is
<document>
<party>
<gtin>1000909090</gtin>
<pos>
<attrGroupMany name="temperatureInformation">
<row>
<attr name="temperatureCode">STORAGE</attr>
<attrQualMany name="temperature">
<value qual="FAH">10</value>
<value qual="CC">20</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE1</attr>
</row>
<row>
<attr name="StatsCode">CODE2</attr>
</row>
</attrGroupMany>
</row>
<row>
<attr name="temperatureCode">STORAGE</attr>
<attrQualMany name="temperature">
<value qual="FAH">10</value>
<value qual="CC">20</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE3</attr>
</row>
<row>
<attr name="StatsCode">CODE4</attr>
</row>
</attrGroupMany>
</row>
<row>
<attr name="temperatureCode">HANDLING</attr>
<attrQualMany name="temperature">
<value qual="FAH">10</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE5</attr>
</row>
<row>
<attr name="StatsCode">CODE6</attr>
</row>
</attrGroupMany>
</row>
<row>
<attr name="temperatureCode">HANDLING</attr>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE7</attr>
</row>
<row>
<attr name="StatsCode">CODE8</attr>
</row>
</attrGroupMany>
</row>
</attrGroupMany>
</pos>
</party>
</document>
we need to concat the value of temperatureCode, All value of temperature (if present) for all row and if they are duplicate, then merge the row inside temperatureStats of the child in the parent.
Expected output is in the same structure. You can see the second node is merged with first
<document>
<party>
<gtin>1000909090</gtin>
<pos>
<attrGroupMany name="temperatureInformation">
<row>
<attr name="temperatureCode">STORAGE</attr>
<attrQualMany name="temperature">
<value qual="FAH">10</value>
<value qual="CC">20</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE1</attr>
</row>
<row>
<attr name="StatsCode">CODE2</attr>
</row>
<row>
<attr name="StatsCode">CODE3</attr>
</row>
<row>
<attr name="StatsCode">CODE4</attr>
</row>
</attrGroupMany>
</row>
<row>
<attr name="temperatureCode">HANDLING</attr>
<attrQualMany name="temperature">
<value qual="FAH">10</value>
</attrQualMany>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE5</attr>
</row>
<row>
<attr name="StatsCode">CODE6</attr>
</row>
</attrGroupMany>
</row>
<row>
<attr name="temperatureCode">HANDLING</attr>
<attrGroupMany name="temperatureStats">
<row>
<attr name="StatsCode">CODE7</attr>
</row>
<row>
<attr name="StatsCode">CODE8</attr>
</row>
</attrGroupMany>
</row>
</attrGroupMany>
</pos>
</party>
</document>
Any input will be very valuable.