I'm trying to remove duplicate elements from my xml. I included a sample of it below.
The element I'm after is the target element "main > child > date > record > target". What I want to do is remove all occurrences of targets with the same content except the first time it occurs.
For example remove all the target elements with "A" leaving only the first.
I'm open to using xsl or php. But can anyone recommend how I should go about this?
<?xml version="1.0" encoding="UTF-8"?>
<main>
<name>John Doe</name>
<child year="2008">
<date date="Sat Jul 18">
<record>
<target>A</target>
</record>
</date>
<date date="Sun Jul 19">
<record>
<target>B</target>
</record>
<record>
<target>A</target>
</record>
</date>
</child>
<child year="2009">
<date date="Sat Jan 18">
<record>
<target>C</target>
</record>
</date>
<date date="Sun Jan 19">
<record>
<text>Some text</text>
<target>A</target>
</record>
</date>
</child>
</main>
The element I'm after is the target element "main > child > date > record > target". What I want to do is remove all occurrences of targets with the same content except the first time it occurs.
For example remove all the target elements with "A" leaving only the first.
I'm open to using xsl or php. But can anyone recommend how I should go about this?
<?xml version="1.0" encoding="UTF-8"?>
<main>
<name>John Doe</name>
<child year="2008">
<date date="Sat Jul 18">
<record>
<target>A</target>
</record>
</date>
<date date="Sun Jul 19">
<record>
<target>B</target>
</record>
<record>
<target>A</target>
</record>
</date>
</child>
<child year="2009">
<date date="Sat Jan 18">
<record>
<target>C</target>
</record>
</date>
<date date="Sun Jan 19">
<record>
<text>Some text</text>
<target>A</target>
</record>
</date>
</child>
</main>