I need to remove duplicates from an xml file, I want to retain the later record than the earlier record. The xslt I have outputs the earlier record. I wanted the later one. Can you please help me.
<FileRead xmlns="http://TargetNamespace.com/EmpDetails">
<EmployeeInformation>
<Empl_ID>63496</Empl_ID>
<First_Name>ALEXIS</First_Name>
<Last_Name>TORRES</Last_Name>
<Record_Updated_Date>7/19/2017</Record_Updated_Date>
</EmployeeInformation>
<EmployeeInformation>
<Empl_ID>63497</Empl_ID>
<First_Name>JOHN</First_Name>
<Last_Name>DOE</Last_Name>
<Record_Updated_Date>8/19/2017</Record_Updated_Date>
</EmployeeInformation>
<EmployeeInformation>
<Empl_ID>63496</Empl_ID>
<First_Name>ALEXIS</First_Name>
<Last_Name>TORRES</Last_Name>
<Record_Updated_Date>8/19/2017</Record_Updated_Date>
</EmployeeInformation>
<EmployeeInformation>
<Empl_ID>63498</Empl_ID>
<First_Name>BILL</First_Name>
<Last_Name>SMITH</Last_Name>
<Record_Updated_Date>7/19/2017</Record_Updated_Date>
</EmployeeInformation>
</FileRead>
My XSLT is
<xsl:stylesheet version="1.0" xmlns:ns0="http://TargetNamespace.com/EmpDetails" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="employees" match="ns0:EmployeeInformation" use="ns0:Empl_ID"/>
<xsl:template match="/*">
<ns0:FileRead>
<xsl:copy-of select="*[generate-id() = generate-id(key('employees', ns0:Empl_ID)[1])]"/>
</ns0:FileRead>
</xsl:template>
</xsl:stylesheet>
Expected Output is
<FileRead xmlns="http://TargetNamespace.com/EmpDetails">
<EmployeeInformation>
<Empl_ID>63497</Empl_ID>
<First_Name>JOHN</First_Name>
<Last_Name>DOE</Last_Name>
<Record_Updated_Date>8/19/2017</Record_Updated_Date>
</EmployeeInformation>
<EmployeeInformation>
<Empl_ID>63496</Empl_ID>
<First_Name>ALEXIS</First_Name>
<Last_Name>TORRES</Last_Name>
<Record_Updated_Date>8/19/2017</Record_Updated_Date>
</EmployeeInformation>
<EmployeeInformation>
<Empl_ID>63498</Empl_ID>
<First_Name>BILL</First_Name>
<Last_Name>SMITH</Last_Name>
<Record_Updated_Date>7/19/2017</Record_Updated_Date>
</EmployeeInformation>
</FileRead>