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 903945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:58:16+00:00 2026-05-15T15:58:16+00:00

I have the following xml: <?xml version=1.0 encoding=UTF-8?> <SomeName> <NodeA> DataA </NodeA> <NodeA> DataB

  • 0

I have the following xml:

<?xml version="1.0" encoding="UTF-8"?>   
<SomeName>   
  <NodeA> 
    DataA 
 </NodeA>   
 <NodeA> 
    DataB 
 </NodeA>   
  <NodeA> 
    DataA 
 </NodeA>   
  <AnotherNode> 
    DataA 
 </AnotherNode> 
  <AnotherNode> 
    DataC 
 </AnotherNode> 
  <AnotherNode> 
    DataC 
 </AnotherNode> 
 <SingleNode> 
    DataA 
 </SingleNode> 

And I need to parse through the xml removing any nodes that have the same name as well as the same content. The problem is, the duplicates are more or less scattered throughout the document and I don’t have a list of nodenames or specific contents I want to get rid of.

Basically my output should look like this:

<?xml version="1.0" encoding="UTF-8"?>   
<SomeName>   
  <NodeA> 
    DataA 
 </NodeA>   
 <NodeA> 
    DataB 
 </NodeA>   
 <AnotherNode> 
    DataA 
 </AnotherNode> 
  <AnotherNode> 
    DataC 
 </AnotherNode>  
 <SingleNode> 
    DataA 
 </SingleNode> 

Anyone got some clever XSLT?

Thanks!

  • 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-05-15T15:58:17+00:00Added an answer on May 15, 2026 at 3:58 pm

    With proper input:

    <SomeName>
        <NodeA>DataA</NodeA>
        <NodeA>DataB</NodeA>
        <NodeA>DataA</NodeA>
        <AnotherNode>DataA</AnotherNode>
        <AnotherNode>DataC</AnotherNode>
        <AnotherNode>DataC</AnotherNode>
        <SingleNode>DataA</SingleNode>
    </SomeName>
    

    This stylesheet:

    <xsl:stylesheet
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              version="1.0">
        <xsl:output indent="yes"/>
        <xsl:key name="nodes" match="SomeName/*" use="concat(name(),'&amp;',.)"/>
        <xsl:template match="SomeName">
            <xsl:copy>
                <xsl:copy-of select="*[count(.|key('nodes',concat(name(),'&amp;',.))[1])=1]"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    Result:

    <SomeName>
    <NodeA>DataA</NodeA>
    <NodeA>DataB</NodeA>
    <AnotherNode>DataA</AnotherNode>
    <AnotherNode>DataC</AnotherNode>
    <SingleNode>DataA</SingleNode>
    </SomeName>
    

    With the “Identity Transform”:

    <xsl:stylesheet
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              version="1.0">
        <xsl:output indent="yes"/>
        <xsl:key name="nodes" match="SomeName/*" use="concat(name(),'&amp;',.)"/>
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="SomeName/*[count(.|key('nodes',concat(name(),'&amp;',.))[1])!=1]"/>
    </xsl:stylesheet>
    

    Edit: Added an example with “indentity transform” in case more work has to be done.

    Note: Muenchian Method of grouping.

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

Sidebar

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try the DataGrid from the WPF Toolkit May 16, 2026 at 3:30 pm
  • Editorial Team
    Editorial Team added an answer Gecko supports up/down bubbling, but IE only supports up bubbling.… May 16, 2026 at 3:29 pm
  • Editorial Team
    Editorial Team added an answer What version of SQL Server? SQL 2005 and up: SELECT… May 16, 2026 at 3:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0
i have a XML file as follows: <?xml version=1.0 encoding=utf-8 ?> <publisher> <name>abc</name> <link>http://</link>
I have an XmlDocument object and xml in the format: <?xml version=1.0 encoding=utf-8?> <S
Let's say I have following Spring config (version of Spring is 3.0.3): <?xml version=1.0
I have the following xml that's sent to me from a web service. I'm
I have the following code used to get xml from a DataSet into a
I have a serialized object which needs to be sent as an encrypted XML
I am having great problems solving this one: I have a mysql database encoding
I have an XSLT transform I am using to process an XML file, inserting
How can I apply XSLT on following XML so string between ~ and $

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.