cancel
Showing results for 
Search instead for 
Did you mean: 

Merge Data from Two Different Segments of Source Structure

former_member192105
Participant
0 Kudos

Dear Experts,
I have a mapping requirement to merge employee data from one segment (Records) into corresponding employee record from other segment (EmployeeDetails). This is shown in the attached image with sample data:

For ex. : For EmployeeDetails > Employee > EmpID = 1111 the values for Area and SubArea should be mapped from Records > row > Section and SubSection respectively.

There will be 1000s of records for which such a merging needs to be done with each EmpID repeating only once.

If there is no corresponding value found in Records > row for an user then the values from EmployeeDetails > Employee should be sent as is.

Any inputs on how this can be achieved in mapping?

Thank you!

former_member192105
Participant
0 Kudos

Hello Experts,
Can anyone please help me with this requirement?
Thank you in advance for your time and help.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member608567
Participant
0 Kudos

Hi Abhishek!

This can be done by using UDF(user defined function) as well in Graphical Mapping. I have attached the UDF code below and also mapping parts.

for(int i=0;i<in1.length;i++)   //in1.length-- count of employee in employee details
{
  for(int j=0;j<input1.length;j++)	//input1.length-- count of employee in records	
   {
    if(in2[i]!=input1[j])
       {	
	if(j==input1.length-1)
	   {
  	        out1.addValue(in1[i]);   
    	        out2.addValue(in2[i]);
		out3.addValue(in3[i]);
		out4.addValue(in4[i]);
		out5.addValue(in5[i]);
		out6.addValue(in6[i]);
	   }								
       }		
     else if(in2[i]==input1[j])	 									                                 
       {
		out1.addValue(in1[i]);
		out2.addValue(in2[i]);
		out3.addValue(in3[i]);
		out4.addValue(in4[i]);
		out5.addValue(input2[j]);
		out6.addValue(input3[j]);
		break;								
	}					
   }		
}
former_member190293
Active Contributor
0 Kudos

Hi Abhishek!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ns0="http://test.com"
    version="1.0">
    <xsl:template match="/">
        <ns0:MT_Employee_Out>
            <EmployeeDetails>
                <xsl:apply-templates select="/ns0:MT_Employee/Employee_Details/Employee"/>
            </EmployeeDetails>
        </ns0:MT_Employee_Out>
    </xsl:template>
    <xsl:template match="Employee">
        <xsl:variable name="id" select="EmpID"/>
        <Employee>
            <EmpID><xsl:value-of select="EmpID"/></EmpID>
            <Record><xsl:value-of select="Record"/></Record>
            <FirstName><xsl:value-of select="FirstName"/></FirstName>
            <LastName><xsl:value-of select="LastName"/></LastName>
            <xsl:apply-templates select="/ns0:MT_Employee/Records/row[EmpID = $id]"/>
        </Employee>
    </xsl:template>
    <xsl:template match="row">
        <Area><xsl:value-of select="Section"/></Area>
        <SubArea><xsl:value-of select="SubSection"/></SubArea>
    </xsl:template>
</xsl:stylesheet>

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

Hi Abhishek!

Your requirement could be easily fulfilled by using XSL transformation.

Regards, Evgeniy.

former_member192105
Participant
0 Kudos

Hello Evgeniy,
Thank you for the response!
Do you have any XSLT code which can be of use in my case?
Thank you!