We help IT Professionals succeed at work.
Get Started

Remove duplicates with XSLT 1.0

Peter_W_S
Peter_W_S asked
on
126 Views
Last Modified: 2015-03-30
Hi,

I have a problem with duplicates within my xml file that I need to have removed. I'm limited to using XSLT 1.0.

Consider having the following XML file:

<?xml version="1.0" encoding="UTF-8"?>
<ArrayOfIntegrationImportData 
  xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:enterprise="http://schemas.datacontract.org/2004/07/Elite.Enterprise.Integrations">
  <IntegrationImportData i:type="enterprise:IntegrationItem">
    <ExternalSystemId>value1</ExternalSystemId>
    <enterprise:Description>abcdefg</enterprise:Description>
    <enterprise:IsActive>1</enterprise:IsActive>
    <enterprise:SupplierItems>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>abc110</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>25002</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>def220</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>3800</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>abc110</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>25002</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
    </enterprise:SupplierItems>
  </IntegrationImportData>
  <IntegrationImportData i:type="enterprise:IntegrationItem">
    <ExternalSystemId>value2</ExternalSystemId>
    <enterprise:Description>gfdsa</enterprise:Description>
    <enterprise:IsActive>1</enterprise:IsActive>
    <enterprise:SupplierItems>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>opq550</ExternalSystemId>
        <enterprise:PartNumber>159753</enterprise:PartNumber>
        <enterprise:Supplier>25002</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>opq550</ExternalSystemId>
        <enterprise:PartNumber>159753</enterprise:PartNumber>
        <enterprise:Supplier>25002</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>ght342</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>3800</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
    </enterprise:SupplierItems>
  </IntegrationImportData>
</ArrayOfIntegrationImportData>

Open in new window


As you can see there are duplicate enterprise:IntegrationSupplierItem within the enterprise:SupplierItems. I need these duplicates removed. The ExternalSystemId can be seen as the key of each of the enterprise:IntegrationSupplierItem, so the result should be:

<?xml version="1.0" encoding="UTF-8"?>
<ArrayOfIntegrationImportData 
  xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:enterprise="http://schemas.datacontract.org/2004/07/Elite.Enterprise.Integrations">
  <IntegrationImportData i:type="enterprise:IntegrationItem">
    <ExternalSystemId>value1</ExternalSystemId>
    <enterprise:Description>abcdefg</enterprise:Description>
    <enterprise:IsActive>1</enterprise:IsActive>
    <enterprise:SupplierItems>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>abc110</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>25002</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>def220</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>3800</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
    </enterprise:SupplierItems>
  </IntegrationImportData>
  <IntegrationImportData i:type="enterprise:IntegrationItem">
    <ExternalSystemId>value2</ExternalSystemId>
    <enterprise:Description>gfdsa</enterprise:Description>
    <enterprise:IsActive>1</enterprise:IsActive>
    <enterprise:SupplierItems>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>opq550</ExternalSystemId>
        <enterprise:PartNumber>159753</enterprise:PartNumber>
        <enterprise:Supplier>25002</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
      <enterprise:IntegrationSupplierItem>
        <ExternalSystemId>ght342</ExternalSystemId>
        <enterprise:PartNumber>11303633</enterprise:PartNumber>
        <enterprise:Supplier>3800</enterprise:Supplier>
      </enterprise:IntegrationSupplierItem>
    </enterprise:SupplierItems>
  </IntegrationImportData>
</ArrayOfIntegrationImportData>

Open in new window


I'm pretty sure Muenchian grouping is the way to go - I just can't figure out the exact implementation that gives me the wanted result. Any input would be much appreciated.
Comment
Watch Question
Information Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE