473,473 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How 2 remove duplicate element based on combination of multiple attributes using xslt

2 New Member
This is how my Input XML looks like:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <root>
  3. <Account  InceptionDate="03/01/2005"  BusinessWorkGroup="US" BusinessUnit="BOS" AccountId="XYZ4321" ISOCurrency="USD" DomicileCountry="USA">
  4. <AssignContact ContactId="123" Type="Administrative Assistant"/>
  5. <AssignContact ContactId="123" Type="Portfolio Manager"/>
  6. <AssignContact ContactId="123" Type="Portfolio Manager"/>
  7. </Account>  
  8. <Account  InceptionDate="03/01/2006"  BusinessWorkGroup="US" BusinessUnit="BOS" AccountId="ABC1231" ISOCurrency="USD" DomicileCountry="USA">
  9. <AssignContact ContactId="543" Type="Administrative Assistant"/>
  10. <AssignContact ContactId="543" Type="Portfolio Manager"/>
  11. <AssignContact ContactId="211" Type="Portfolio Manager"/>
  12. </Account>  
  13. <Account  InceptionDate="03/01/2010"  BusinessWorkGroup="US" BusinessUnit="BOS" AccountId="DUM111" ISOCurrency="USD" DomicileCountry="USA">
  14. <AssignContact ContactId="987" Type="Administrative Assistant"/>
  15. <AssignContact ContactId="987" Type="Administrative Assistant"/>
  16. <AssignContact ContactId="211" Type="Portfolio Manager"/>
  17. </Account> 
  18. </root>
My output should look like (Duplicate [combination of ContactId & Type ] should be removed from final xml ):

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <root>
  3. <Account  InceptionDate="03/01/2005"  BusinessWorkGroup="US" BusinessUnit="BOS" AccountId="XYZ4321" ISOCurrency="USD" DomicileCountry="USA">
  4. <AssignContact ContactId="123" Type="Administrative Assistant"/>
  5. <AssignContact ContactId="123" Type="Portfolio Manager"/>
  6. </Account>  
  7. <Account  InceptionDate="03/01/2006"  BusinessWorkGroup="US" BusinessUnit="BOS" AccountId="ABC1231" ISOCurrency="USD" DomicileCountry="USA">
  8. <AssignContact ContactId="543" Type="Administrative Assistant"/>
  9. <AssignContact ContactId="543" Type="Portfolio Manager"/>
  10. <AssignContact ContactId="211" Type="Portfolio Manager"/>
  11. </Account>
  12. <Account  InceptionDate="03/01/2010"  BusinessWorkGroup="US" BusinessUnit="BOS" AccountId="DUM111" ISOCurrency="USD" DomicileCountry="USA">
  13. <AssignContact ContactId="987" Type="Administrative Assistant"/>
  14. <AssignContact ContactId="211" Type="Portfolio Manager"/>
  15. </Account> 
  16. </root>
Feb 13 '15 #1
1 9800
deepak Khatri
2 New Member
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
  2.     <xsl:output method="xml" indent="yes" version="1.0"/>
  3.     <xsl:strip-space elements="*"/>
  4.  
  5.     <xsl:key name="Contact" match="AssignContact" use="concat(../@AccountId, '|', @ContactId, '|', @Type)" />
  6.  
  7.     <xsl:template match="@*|node()">
  8.         <xsl:copy>
  9.             <xsl:apply-templates select="@*|node()"/>
  10.             </xsl:copy>
  11.     </xsl:template>
  12.  
  13.     <xsl:template match="AssignContact[generate-id() != generate-id(key('Contact', concat(../@AccountId, '|', @ContactId, '|', @Type))[1])]" />
  14. </xsl:stylesheet>
Feb 17 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Igor | last post by:
Is there any way to resort and xml document using xslt based on element position. For example if I have xml like this: <root> <element> 1st thing </element> <element> 2nd thing </element>...
3
by: David Elliott | last post by:
I wrote an application to scrape a database and create an XSD file which will be annotated by a map file in order to create a Typed DataSet. I was wondering if I could do the annotation using...
1
by: Kathie G via AccessMonster.com | last post by:
Hello, I have a delima that I am not sure how to resolve. Records get entered manually or through an import. The records contain, RecordID, Client ID, Specimen Date, Visit Date, Client DOB, and...
1
by: Bilal Bhutta | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
3
by: =?iso-8859-1?q?Christian_R=FChl?= | last post by:
Hi folks! I have a little noob problem here with XSLT. I have a XML file that looks like this: <archiveFiles> <module path="c:/temp/module_m17_blabla.tmp"/> <module...
3
by: TechieGrl | last post by:
Hello. It's been awhile since I've been in the XML world, but before I go down a possibly unnecessary path, I wanted to ask about using CSS and XML files. Is it possible to style multiple...
3
by: WideBoy | last post by:
Hi, I have a software generated schema which creates a few empty elements, e.g. <xsd:sequence/>. I would like to be able to delete these elements from the schema post-generation using XSLT. ...
6
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur...
2
by: Samudaya | last post by:
Hi, I have a application which has a xml file reading and wrting. I want to remove some element in xml file by using php. <?xml version="1.0" encoding="UTF-8"?> <element1>...
2
by: njsimha | last post by:
Hi, I have a query regarding the selection of a particular tag based on a condition. In the following XML code: <root> <template1> <elem1>1000</elem1> <elem2>
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.