Skip to Content

Merge Data from Two Different Segments of Source Structure

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 this using XSLT mapping?

I tried asking the query in SAP PO and was suggested to use XSLT mapping. Hence posting the question in this forum.

Thank you

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Apr 16 at 09:48 PM

    Hi Abhishek,

    Below XSLT will do this transform.

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

    Paste your XML next time instead of screenshot.

    Regards,

    Yatan

    Add comment
    10|10000 characters needed characters exceeded

    • Hello,
      With bit of change to your XSLT logic, the conversion works perfectly well. However, it takes around 30 mins to process around 9000 user records. Is this normal? Or is it because XSLT is used it takes such a long execution time.
      Thank you!

  • May 13 at 04:47 AM

    Hi Abhishek,

    9K is a big XML, however 30 min is a big time to process it, you can try using groovy script or standard mapping of CPI to see if the performance is better.

    XSLT is not the default mapping for CPI, so we can not expect good performance.

    Regards,

    Yatan

    Add comment
    10|10000 characters needed characters exceeded

  • May 14 at 09:50 AM

    Hi Abhishek!

    First of all, you should use some XSLT debugging tool with profiling possiblities (for example, Oxygen XML Editor) to find bottle necks.

    By the way, first thing I would try is to store:

    <xsl:value-ofselect="/ns:MT_Employee/EmployeeDetails/Employee[EmpID=$EmpID]

    to variable for current row and use that variable to fetch the needed child values instead of repeating the search through entire XML tree for every target element.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded