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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:59:45+00:00 2026-06-08T07:59:45+00:00

I have a XML I am wanting to transform it with xslt. The input

  • 0

I have a XML I am wanting to transform it with xslt.
The input looks like this.

<xmeml>
<Doc>
    <Test>
        <Unit>abc</Unit>
        <Unit2>1234</Unit2>
        <Unit3>tuvw</Unit3>
    </Test>
    <Test>
        <Unit>bcd</Unit>
        <Unit2>2345</Unit2>
        <Unit3>wxyz</Unit3>
    </Test>
</Doc>
<Doc>
    <Test>
        <Unit>abc</Unit>
        <Unit2>3456</Unit2>
        <Unit3>wxyz</Unit3>
    </Test>
    <Test>
        <Unit>cde</Unit>
        <Unit2>3456</Unit2>
        <Unit3>wxyz</Unit3>
    </Test> 
</Doc>
<Doc>
    <Test>
        <Unit>abc</Unit>
        <Unit2>1234</Unit2>
        <Unit3>wxyz</Unit3>
    </Test>
    <Test>
        <Unit>def</Unit>
        <Unit2>4567</Unit2>
        <Unit3>wxyz</Unit3>
    </Test> 
</Doc>
<Doc>
    <Test>
        <Unit>abc</Unit>
        <Unit2>1234</Unit2>
        <Unit3>uvwx</Unit3>
    </Test>
    <Test>
        <Unit>efg</Unit>
        <Unit2>2345</Unit2>
        <Unit3>wxyz</Unit3>
    </Test> 
</Doc>
</xmeml>

the output should look like this.

<xmeml>
<Doc>
    <Test>
        <Unit>bcd</Unit>
        <Unit2>2345</Unit2>
        <Unit3>wxyz</Unit3>
    </Test>
</Doc>
<Doc>
    <Test>
        <Unit>abc</Unit>
        <Unit2>3456</Unit2>
        <Unit3>wxyz</Unit3>
    </Test>
    <Test>
        <Unit>cde</Unit>
        <Unit2>3456</Unit2>
        <Unit3>wxyz</Unit3>
    </Test> 
</Doc>
<Doc>
    <Test>
        <Unit>abc</Unit>
        <Unit2>1234</Unit2>
        <Unit3>wxyz</Unit3>
    </Test>
    <Test>
        <Unit>def</Unit>
        <Unit2>4567</Unit2>
        <Unit3>wxyz</Unit3>
    </Test> 
</Doc>
<Doc>
    <Test>
        <Unit>efg</Unit>
        <Unit2>2345</Unit2>
        <Unit3>wxyz</Unit3>
    </Test> 
</Doc>
</xmeml>

I am wanting to remove any Test nodes that match the following criteria.
– The Unit3 child node starts-with tuv or uvw.
– AND Where both the Unit AND Unit2 vales are both found repeated/duplicated in another Test node

Thanks in advance for your help.

  • 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-08T07:59:47+00:00Added an answer on June 8, 2026 at 7:59 am

    How about this tweak of Dimitre’s solution …

    <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="kTest" match="Test" use="concat(Unit, '+', Unit2)"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
      "Test[key('kTest', concat(Unit, '+', Unit2))[2]]
       [starts-with(Unit3, 'tuv') or starts-with(Unit3, 'uvw')]"/>
    </xsl:stylesheet>
    

    As I understand it, the rules of transformation are:

    1. Copy all nodes as is, except as indicated following.
    2. Exclude all Test nodes have that the following properties:

    2.1 There exists another Test node (call it Test(other)) in the document such that:

      (Test(reference) / Unit = Test(other) / Unit)   AND
      (Test(reference) / Unit2 = Test(other) / Unit2)
    

    2.2 The Unit3 child of the reference Test node starts with tuv or uvw

    The output for this is exactly as the OP posted. Interestly, if I have understood the problem correctly, Dimitre has just recently provided a solution to almost the same problem as yours here XSL comparison of nodes . Again, if I have understood your problem correctly, the title is misleading. “Removing duplicates” is generally taken to mean de-duping, as in (1,2,2,3) –> (1,2,3) ; whereas what you want, like (1,2,2,3) –> (1,3) is generally described as “selecting unique nodes/values”.

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

Sidebar

Related Questions

i have this XSLT and XML payload that i am wanting to transform. but
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I Have XML similar to this(omitted parts for brevity): <uformrecord> <state>Submitted</state> <created>2012-06-19T11:31:54</created> <updated>2012-06-19T11:32:13</updated> <id>53225sas3c1-d727-42cd-93a6-97cd778e5ee9</id>
I've been fighting this all day. Inside my styles.xml file I have color information
I have an object structure I have deserialized from XML - but I'm wanting
I have an XML document in this format: <?xml version=1.0 encoding=utf-8 ?> <SupportedServices> <Service>
I have the following XML document which I would like to parse into a

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.