Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:37:03+00:00 2026-06-11T17:37:03+00:00

How can I remove the nodes of type package if their names repeat. I

  • 0

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>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:37:04+00:00Added an answer on June 11, 2026 at 5:37 pm

    I. This simple XSLT 1.0 transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="package[preceding::package]"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <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>
    </coverage>
    

    produces the wanted, correct result:

    <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>
    </coverage>
    

    Explanation:

    Proper use of and overriding the identity rule.


    II. Solution using keys:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kElemByName" match="*" use="name()"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
     "package[not(generate-id()=generate-id(key('kElemByName', name())[1]))]"/>
    </xsl:stylesheet>
    

    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:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kElemByName" match="*" use="name()"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
     "package[not(. is (//package)[1])]"/>
    </xsl:stylesheet>
    

    Explanation:

    Proper use of the XPath 2.0 operator is .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for an API that can remove bundle items added in a
Is there anyway or any addin for VS2010 that can remove all the comments
I'm in need of a regular expression that can remove unnecessary/extra parenthesis in a
can I remove the Choose forum dropdown field from my forum nodes content types
I want to remove all text nodes (but not any other type of node)
we can remove formula from one cell by cell.setCellFormula(null) . but if i want
One can remove all calls to printf() using #define printf . What if I
How we can remove an array entry from : var a = [],b =
How to I can remove posts from a specific category from homepages in wordpress?
Is there a way I can remove the background bar image in the SeekBar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.