How can I remove the nodes of type package if their names repeat. I mean that the first occurrence should be kept and the others should be removed. See that package_one name is repeated in the package node
<?xml version="1.0"?>
<coverage branch-rate="0.53968253968278" branch-total="50" line-rate="0.66864343958488" line-total="2000" timestamp="1346297959" version="gcovr 2.3">
<sources>
<source>
./.
</source>
</sources>
<packages>
<package branch-rate="0.52380952380967" branch-total="15" line-rate="0.75148257968866" line-total="1000" complexity="0.0" name="package_one">
<classes>
<class branch-rate="0.0" complexity="0.0" filename="eBayBotAPI.cpp" line-rate="0.0" name="BotAPI.cpp">
<lines>
<line branch="false" hits="0" number="128" condition-coverage="100%"/>
<line branch="false" hits="0" number="192" condition-coverage="100%"/>
</lines>
</class>
</classes>
<class branch-rate="0.5" complexity="0.0" filename="good.cpp" line-rate="1.0" name="good1.cpp">
<lines>
<line branch="false" hits="96" number="8" condition-coverage="100%"/>
</lines>
</class></package>
<package branch-rate="0.571428571429" branch-total="10" complexity="0.0" line-rate="0.00593031875463" line-total="1000" name="package_one">
<classes>
<class branch-rate="0.0" complexity="0.0" filename="eBayBotAPI.cpp" line-rate="0.0" name="BotAPI.cpp">
<lines>
<line branch="false" hits="0" number="128" condition-coverage="100%"/>
</lines>
</class>
</classes>
</package>
</packages>
Expected:
<?xml version="1.0"?>
<coverage branch-rate="0.53968253968278" branch-total="50" line-rate="0.66864343958488" line-total="2000" timestamp="1346297959" version="gcovr 2.3">
<sources>
<source>
./.
</source>
</sources>
<packages><package branch-rate="0.52380952380967" branch-total="15" line-rate="0.75148257968866" line-total="1000" complexity="0.0" name="package_one"><classes>
<class branch-rate="0.0" complexity="0.0" filename="eBayBotAPI.cpp" line-rate="0.0" name="BotAPI.cpp">
<lines>
<line branch="false" hits="0" number="128" condition-coverage="100%"/>
<line branch="false" hits="0" number="192" condition-coverage="100%"/>
</lines>
</class>
</classes><class branch-rate="0.5" complexity="0.0" filename="good.cpp" line-rate="1.0" name="good1.cpp">
<lines>
<line branch="false" hits="96" number="8" condition-coverage="100%"/>
</lines>
</class></package>
</packages>
I. This simple XSLT 1.0 transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation:
Proper use of and overriding the identity rule.
II. Solution using keys:
When this transformation is applied on the same XML document (above), the same wanted, correct result is produced.
Explanation:
Proper use both of the identity rule and of Muenchian grouping.
III. XSLT 2.0 Solution:
Explanation:
Proper use of the XPath 2.0 operator is .