I have an xml attribute that contains elements with id, some of those ids may occure more than once. In that case, I'd like to append _copy to all but the first element with that id.
So my xml file looks like this:
<elems>
<elem id="123"/>
<elem id="2832"/>
<elem id="2272"/>
<elem id="123"/>
<elem id="123"/>
</elems>
Desired output:
<elems>
<elem id="123"/>
<elem id="2832"/>
<elem id="2272"/>
<elem id="123_copy"/>
<elem id="123_copy"/>
</elems>
What would be the best way to do that? I was thinking something along the lines of reading the document into a variable and then checking if the id occurs more than once...
Thanks for help and tips!