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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:56:04+00:00 2026-05-29T15:56:04+00:00

I want to apply a XSL style sheet that delete duplicate nodes in my

  • 0

I want to apply a XSL style sheet that delete duplicate nodes in my xml.
I test some solution but i can’t do it 🙁 my program is in Visual C# Studio.

I have the following XML:

<store>

 <laptop>
  <ID>1</ID>
  <price>X2</price>
 </laptop>

 <laptop>
  <ID>2</ID>
  <price>X1</price>
 </laptop>

 <laptop>
  <ID>8</ID>
  <price>X2</price>
 </laptop>

 <laptop>
  <ID>2</ID>
  <price>X3</price>
 </laptop>

</store>

The desired output is:

    <store>

     <laptop>
      <ID>1</ID>
      <price>X2</price>
     </laptop>

     <laptop>
      <ID>8</ID>
      <price>X2</price>
     </laptop>

     <laptop>
      <ID>2</ID>
      <price>X3</price>
     </laptop>

    </store>
  • 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-29T15:56:05+00:00Added an answer on May 29, 2026 at 3:56 pm

    The solution below does what you are asking for and works the following way:

    1. The first template starts at root and selects all ID tags that does
      not have a ID tag below with the same value (thats why ID 2 comes at
      the end of the output)
    2. Loop through the list of ID nodes and output the parent()
      and all of it’s children

    Comments are welcome, this is my first try at XSL in the last two years.
    I tried a xsl:copy but it failed to include the children’s tag names, but the values showed up, couldn’t figure out why!?

    Taken somewhat out of it’s contents:

      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    

    Working code:

     <xsl:stylesheet 
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
            exclude-result-prefixes="xs">
    
        <xsl:template match="/">
         <store>
         <xsl:variable name="non-duplicates"
         select="//ID[not(.=following::ID)]" />   
    
         <xsl:for-each select="$non-duplicates">
           <xsl:copy-of select="parent::*"/>
         </xsl:for-each>
         </store>
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just created a XSL file that sorts my XML. Now I want to
I have an XML document that I want to generate unique IDs for. Some
I want to select nodes based on some variables. The XML code: <data> <prot
I want apply margin property for my html newsletter But Gmail ignores this CSS
I want to apply texture to the transparent png(bitmap), but I don't want to
i want to apply masking over the textinput that need to get SSN from
I want to apply the following Style to my Polygon : <Style xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:s=clr-namespace:System;assembly=mscorlib
I want to apply a different hyper link style to the following two things:
I have an XML file that contains price value.I want to sort my table
here is my below xml under that table due based on CTD_CTD_PKG_ID(some time under

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.