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

The Archive Base Latest Questions

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

I looked at How to remove duplicate XML nodes using XSLT and other related

  • 0

I looked at How to remove duplicate XML nodes using XSLT and other related questions, but they all seem about removing duplicates if the whole node is a duplicate. What I want to do is remove a node only if one properties within it matches a property within another node.

In my xml, I have 2 termTypes; Nd and Pt. Pts should be used. Where the system finds an Nd, the termName of it should not be used, instead, the name of the Pt referenced in relation termName should be used instead.

But something has gone wrong and some Nds have the same name as the name of the Pts they should be referencing. These terms are irrelevant and I need to delete them

I have:

<term>
<termId>1</termId>
<termUpdate>Add</termUpdate>
<termName>A</termName>
<termType>Nd</termType>
<relation>
  <relationType>USE</relationType>
  <termId>2</termId>
  <termName>A</termName>
</relation>
</term>

<term>
<termId>2</termId>
<termUpdate>Add</termUpdate>
<termName>A</termName>
<termType>Pt</termType>
</term>

<term>
<termId>3</termId>
<termUpdate>Add</termUpdate>
<termName>C</termName>
<termType>Nd</termType>
<relation>
  <relationType>USE</relationType>
  <termId>4</termId>
  <termName>D</termName>
</relation>
</term>

<term>
<termId>4</termId>
<termUpdate>Add</termUpdate>
<termName>D</termName>
<termType>Pt</termType>
</term>

Is it possible to use xslt (or some other method) to go through and see that, if the <termName> of an Nd <term> matches the <termName> of a Pt term in its <relation>, delete the whole term? Terms referenced in <relation> are always Pt terms.

Output:

<term>
<termId>2</termId>
<termUpdate>Add</termUpdate>
<termName>A</termName>
<termType>Pt</termType>
</term>

<term>
<termId>3</termId>
<termUpdate>Add</termUpdate>
<termName>C</termName>
<termType>Nd</termType>
<relation>
  <relationType>USE</relationType>
  <termId>4</termId>
  <termName>D</termName>
</relation>
</term>

<term>
<termId>4</termId>
<termUpdate>Add</termUpdate>
<termName>D</termName>
<termType>Pt</termType>
</term>

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-23T15:15:12+00:00Added an answer on May 23, 2026 at 3:15 pm

    This 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:key name="kPtByName" match="term[termType='Pt']"
      use="termName"/>
    
     <xsl:template match="node()|@*" name="identity">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="term[termType='Nd']">
      <xsl:if test="not(key('kPtByName', termName))">
       <xsl:call-template name="identity"/>
      </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document (wrapped into a top element to make it well-formed):

    <terms>
        <term>
        <termId>1</termId>
        <termUpdate>Add</termUpdate>
        <termName>A</termName>
        <termType>Nd</termType>
        <relation>
          <relationType>USE</relationType>
          <termId>2</termId>
          <termName>A</termName>
        </relation>
        </term>
    
        <term>
        <termId>2</termId>
        <termUpdate>Add</termUpdate>
        <termName>A</termName>
        <termType>Pt</termType>
        </term>
    
        <term>
        <termId>3</termId>
        <termUpdate>Add</termUpdate>
        <termName>C</termName>
        <termType>Nd</termType>
        <relation>
          <relationType>USE</relationType>
          <termId>4</termId>
          <termName>D</termName>
        </relation>
        </term>
    
        <term>
        <termId>4</termId>
        <termUpdate>Add</termUpdate>
        <termName>D</termName>
        <termType>Pt</termType>
        </term>
    </terms>
    

    produces the wanted, correct output:

    <terms>
       <term>
          <termId>2</termId>
          <termUpdate>Add</termUpdate>
          <termName>A</termName>
          <termType>Pt</termType>
       </term>
       <term>
          <termId>3</termId>
          <termUpdate>Add</termUpdate>
          <termName>C</termName>
          <termType>Nd</termType>
          <relation>
             <relationType>USE</relationType>
             <termId>4</termId>
             <termName>D</termName>
          </relation>
       </term>
       <term>
          <termId>4</termId>
          <termUpdate>Add</termUpdate>
          <termName>D</termName>
          <termType>Pt</termType>
       </term>
    </terms>
    

    Explanation:

    1. The identity rule copies every node “as is”.

    2. There is just one template that overrides the identity template. It matches any term whose termType child has a value of Nd. This template only calls the identity template if there is no term with the same value of its tername child and whose termType child has a value of Pt. This test is performed using a conveniently defined xsl:key

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

Sidebar

Related Questions

This is not a duplicate post. I've looked through similar questions on SO but
I've looked through all the stuff to remove characters from strings but I don't
a.nodeName is undefined I've looked this up but the explanations didn't seem at all
I looked at a number of existing questions about NameError exceptions when scripts are
I've looked through some of the other posts but couldn't find an answer, so
I've looked all over the web for a reason why I can't remove duplicates
I thought that wasn't that hard to do, but I want to remove all
I looked at SQL Server dateformat codes but I couldn't find dd.mm.yyyy hh:mm format
I looked through the other posts and bug reports and couldn't figure out what's
I want to hide (or remove) all the borders of all the rows (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.