tags:

views:

2797

answers:

2

I have an xml file like

<ns0:Employees xmlns:ns0="http://TestIndexMap.Employees"&gt;
  <Employee FirstName="FirstName_0" LastName="LastName_1" dept="dept_2" empNumber="1">
    <Schedules>
      <Schedule Date_join="2008-01-20" Date_end="2008-01-30" />
    </Schedules>
  </Employee>
    <Employee FirstName="FirstName_0" LastName="LastName_1" dept="dept_2" empNumber="2">
     <Schedules>
      <Schedule Date_join="2008-01-20" Date_end="2008-01-30" />
     </Schedules>
    </Employee>
    <Employee FirstName="FirstName_2" LastName="LastName_1" dept="dept_2" empNumber="2">
     <Schedules>
      <Schedule Date_join="2007-01-21" Date_end="2007-12-30" />

     </Schedules>
    </Employee>
<Employee FirstName="FirstName_2" LastName="LastName_1" dept="dept_2" empNumber="2">
     <Schedules>
      <Schedule Date_join="2007-01-21" Date_end="2007-12-30" />
                            <Schedule Date_join="2008-06-20" Date_end="2008-01-30" />

     </Schedules>
    </Employee>
</ns0:Employees>

I would want to remove the duplicates based on the fistname, last name and date_join and data_end .

please can someone advice how we can achive this. Thanks in advance.

1800 INFORMATION: The language appears to be XSLT. See the tags.

A: 

Your formatting was lost.

What language are you working with?

Mitchel Sellers
+3  A: 

Here are some samples of how to remove duplicates based on element name and id field. It should be not too hard to extend this to arbitrary fields.

Q: Expansion. A part of my xml looks like this:

 <location>
   <state>xxxx</state>
 </location>

 <location>
    <state>yyyy</state>
 </location>

  <location>
    <state>xxxx</state>
 </location>

The desired output is:

xxxx
yyyy

That is, duplicate values of state should not be printed. Can this be done?

   <xsl:variable name="unique-list"
     select="//state[not(.=following::state)]" />   

   <xsl:for-each select="$unique-list">
 <xsl:value-of select="." />
   </xsl:for-each>
1800 INFORMATION
Thanks for the advice. my case first step If first name and last_name matches then I would need to merge the schedules to the same mathing schedules and in the next step is to remove all duplicates in schedule node based on the fist name, last ame,date_joined,date_ended.