Merging XML rowsets with matching attributes



I have an xml rowset defined similar to the following:



<root>
<dataset1>
<rows>
<row id="0" title="Some Title" lookupValues="Something1;Something2"/>
<row id="1" title="Some other title" lookupValues="Something1;Something3"/>
</rows>
</dataset1>
<dataset2>
<rows>
<row lookupValue="Something1"/>
<row lookupValue="Something2"/>
<row lookupValue="Something3"/>
<row lookupValue="Not Something"/>
</rows>
</dataset2>
</root>


and I'm trying to to a transform into a format more like the following:



<newroot>
<rows>
<row uniqueid="1" id="0" title="Some Title" lookupValue="Something1"/>
<row uniqueid="2" id="0" title="Some Title" lookupValue="Something2"/>
<row uniqueid="3" id="1" title="Some other title" lookupValue="Something1"/>
<row uniqueid="4" id="1" title="Some other title" lookupValue="Something3"/>
</rows>
</newroot>


Note the duplicate rows; this is a requirement for the app. Also note the dropping of the missed lookupValue row.


Does anyone know a truly efficient way of achieving this transform?


Thanks.


No comments:

Post a Comment