Eliminate duplicate records in map instance

Monday, June 27, 2011
Q:

Hi, I have a scenario where I can have duplicate records in the incoming instance. How can I check and eliminate the duplicate records while mapping to another instance.
For example: if the incoming instance is

<EmpRecords>
- <record>
  <Request>1</Request>
  <employeename>xyz</employeename>
  <Transaction>1234</Transaction>
  </record>
- <record>
  <Request>2</Request>
  <employeename>123</employeename>
  <Transaction>4567</Transaction>
  </record>
- <record>
  <Request>1</Request>
  <employeename>xyz</employeename>
  <Transaction>1234</Transaction>
  </record>
  </EmpRecords>


How can I check the duplicate record xyz employeename and eliminate it while mapping or in orchestration?
Thanks
Ans



You can use a custom Xsl file http://msdn.microsoft.com/en-us/library/aa560154(v=bts.70).aspx
Using Muenchain grouping technique:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0">
 <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
 <xsl:key name="uniquekey" match="/EmpRecords/record" use="employeename"/>
 <xsl:template match="/">
  <xsl:apply-templates select="/EmpRecords" />
 </xsl:template>
 <xsl:template match="/EmpRecords">
  <xsl:element name="EmpRecords">
   <xsl:for-each select="/EmpRecords/record[count(. | key('uniquekey',employeename)[1]) = 1]">
    <xsl:element name="record">
     <xsl:element name="Request">
      <xsl:value-of select="Request"/>
     </xsl:element>
     <xsl:element name="employeename">
      <xsl:value-of select="employeename"/>
     </xsl:element>
     <xsl:element name="Transaction">
      <xsl:value-of select="Transaction"/>
     </xsl:element>
    </xsl:element>
   </xsl:for-each>
  </xsl:element>
 </xsl:template>
</xsl:stylesheet>


or

You can do it by using Custom XSLT on your map (using muenchian grouping algorithm):
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:key name="recordByRequest" match="record" use="Request" />
  <xsl:template match="EmpRecords">
    <EmpRecords>
      <xsl:for-each select="record[count(. | key('recordByRequest', Request)[1]) = 1]">
        <xsl:copy>
          <xsl:copy-of select="node()" />
        </xsl:copy>
      </xsl:for-each>
    </EmpRecords>
  </xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment

Post Your Comment...