Skip to Content
0
Aug 21, 2020 at 05:55 PM

XSLT mapping error

117 Views

Hi Experts,

I have to merge two xmls based based on the userId.

Original XML -

<?xml version='1.0' encoding='UTF-8'?>
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
    <multimap:Message1>
        <n0:ZHTR_LEAVE_SAL_ADVANCEResponse xmlns:n0="urn:sap-com:document:sap:rfc:functions" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
            <E_LEAVEDATA>
                <item>
                    <PERNR>100087</PERNR>
                    <AMOUNT>0.0</AMOUNT>
                    <DAYS/>
                    <DATE>0000-00-00</DATE>
                    <NOFDAYS>0</NOFDAYS>
                    <HOLIDAYS/>
                </item>
                <item>
                    <PERNR>100103</PERNR>
                    <AMOUNT>0.0</AMOUNT>
                    <DAYS/>
                    <DATE>0000-00-00</DATE>
                    <NOFDAYS>0</NOFDAYS>
                    <HOLIDAYS/>
                </item>
                <item>
                    <PERNR>100104</PERNR>
                    <AMOUNT>0.0</AMOUNT>
                    <DAYS/>
                    <DATE>0000-00-00</DATE>
                    <NOFDAYS>0</NOFDAYS>
                    <HOLIDAYS/>
                </item>
                <item>
                    <PERNR>100120</PERNR>
                    <AMOUNT>0.0</AMOUNT>
                    <DAYS/>
                    <DATE>0000-00-00</DATE>
                    <NOFDAYS>0</NOFDAYS>
                    <HOLIDAYS/>
                </item>
            </E_LEAVEDATA>
        </n0:ZHTR_LEAVE_SAL_ADVANCEResponse>
    </multimap:Message1>
    <multimap:Message2>
        <EmployeeTime>
            <EmployeeTime>
                <approvalStatus>CANCELLED</approvalStatus>
                <lastModifiedDateTime>2020-04-27T05:34:15.000</lastModifiedDateTime>
                <externalCode>6e986c5615e3461eacaa13ab4a621e6d</externalCode>
                <cust_SickLeaveReason/>
                <deductionQuantity>1</deductionQuantity>
                <endDate>2020-04-27T00:00:00.000</endDate>
                <timeTypeNav>
                    <TimeType>
                        <country>SGP</country>
                        <externalCode>2020</externalCode>
                        <externalName_defaultValue>Marriage Leaves for Tradings</externalName_defaultValue>
                    </TimeType>
                </timeTypeNav>
                <displayQuantity>1</displayQuantity>
                <lastModifiedBy>SemantiB</lastModifiedBy>
                <quantityInDays>1</quantityInDays>
                <createdDateTime>2020-04-27T05:33:17.000</createdDateTime>
                <timeType>2020</timeType>
                <workflowRequestId/>
                <userId>100087</userId>
                <createdBy>SemantiB</createdBy>
                <startDate>2020-04-27T00:00:00.000</startDate>
                <originalQuantityInDays>1</originalQuantityInDays>
            </EmployeeTime>
            <EmployeeTime>
                <approvalStatus>CANCELLED</approvalStatus>
                <lastModifiedDateTime>2020-05-09T09:06:16.000</lastModifiedDateTime>
                <externalCode>4749af0fb5d04a8f91d42d86a842cc48</externalCode>
                <cust_SickLeaveReason/>
                <deductionQuantity>105</deductionQuantity>
                <endDate>2020-12-02T00:00:00.000</endDate>
                <timeTypeNav>
                    <TimeType>
                        <country>SGP</country>
                        <externalCode>2002</externalCode>
                        <externalName_defaultValue>Maternity Leave continuous</externalName_defaultValue>
                    </TimeType>
                </timeTypeNav>
                <displayQuantity>105</displayQuantity>
                <lastModifiedBy>SemantiB</lastModifiedBy>
                <quantityInDays>75</quantityInDays>
                <createdDateTime>2020-05-08T10:12:26.000</createdDateTime>
                <timeType>2002</timeType>
                <workflowRequestId/>
                <userId>100103</userId>
                <createdBy>SemantiB</createdBy>
                <startDate>2020-08-20T00:00:00.000</startDate>
                <originalQuantityInDays>75</originalQuantityInDays>
            </EmployeeTime>
            <EmployeeTime>
                <approvalStatus>CANCELLED</approvalStatus>
                <lastModifiedDateTime>2020-05-12T04:22:36.000</lastModifiedDateTime>
                <externalCode>b7457bf1049846d390843e51286d01d1</externalCode>
                <cust_SickLeaveReason/>
                <deductionQuantity>40</deductionQuantity>
                <endDate>2020-10-06T00:00:00.000</endDate>
                <timeTypeNav>
                    <TimeType>
                        <country>SGP</country>
                        <externalCode>2003</externalCode>
                        <externalName_defaultValue>Maternity Leave non-continuous</externalName_defaultValue>
                    </TimeType>
                </timeTypeNav>
                <displayQuantity>40</displayQuantity>
                <lastModifiedBy>SemantiB</lastModifiedBy>
                <quantityInDays>40</quantityInDays>
                <createdDateTime>2020-05-09T12:27:36.000</createdDateTime>
                <timeType>2003</timeType>
                <workflowRequestId/>
                <userId>100104</userId>
                <createdBy>SemantiB</createdBy>
                <startDate>2020-08-12T00:00:00.000</startDate>
                <originalQuantityInDays>40</originalQuantityInDays>
            </EmployeeTime>
            <EmployeeTime>
                <approvalStatus>APPROVED</approvalStatus>
                <lastModifiedDateTime>2020-05-12T05:14:03.000</lastModifiedDateTime>
                <externalCode>06e20a72d55b4da191e3b96438229f12</externalCode>
                <cust_SickLeaveReason>8</cust_SickLeaveReason>
                <deductionQuantity>28</deductionQuantity>
                <endDate>2020-06-18T00:00:00.000</endDate>
                <timeTypeNav>
                    <TimeType>
                        <country>SGP</country>
                        <externalCode>2007</externalCode>
                        <externalName_defaultValue>Sick Leave</externalName_defaultValue>
                    </TimeType>
                </timeTypeNav>
                <displayQuantity>28</displayQuantity>
                <lastModifiedBy>SemantiB</lastModifiedBy>
                <quantityInDays>28</quantityInDays>
                <createdDateTime>2020-05-12T05:14:03.000</createdDateTime>
                <timeType>2007</timeType>
                <workflowRequestId/>
                <userId>100120</userId>
                <createdBy>SemantiB</createdBy>
                <startDate>2020-05-12T00:00:00.000</startDate>
                <originalQuantityInDays>28</originalQuantityInDays>
            </EmployeeTime>
        </EmployeeTime>
    </multimap:Message2>
</multimap:Messages>

Output Required-

<EmployeeTime>
    <EmployeeTime>
        <approvalStatus>CANCELLED</approvalStatus>
        <userId>100087</userId>
        <PERNR>100087</PERNR>
        <AMOUNT>0.0</AMOUNT>
    </EmployeeTime>
    <EmployeeTime>
        <approvalStatus>CANCELLED</approvalStatus>
        <userId>100103</userId>
        <PERNR>100103</PERNR>
        <AMOUNT>0.0</AMOUNT>
    </EmployeeTime>
    <EmployeeTime>
        <approvalStatus>CANCELLED</approvalStatus>
        <userId>100104</userId>
        <PERNR>100104</PERNR>
        <AMOUNT>0.0</AMOUNT>
    </EmployeeTime>
</EmployeeTime>

XSLT used-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
    <xsl:output method="xml" encoding="utf-8" indent="no"/>


    <xsl:template match="/">
        <xsl:variable name="messages1"><xsl:copy-of select="multimap:Messages/multimap:Messages1" /></xsl:variable>
        <EmployeeTime>
            <xsl:for-each select="multimap:Messages/multimap:Message2/EmployeeTime">
                <EmployeeTime>
                    <approvalStatus>
                        <xsl:value-of select="EmployeeTime/EmployeeTime/approvalStatus"/>
                    </approvalStatus>
                    <userId>
                        <xsl:value-of select="EmployeeTime/EmployeeTime/userId"/>-
                        <xsl:value-of select="count(msxsl:node-set($messages1)//*)"/>]
                    </userId>
                    <xsl:if test="userId=msxsl:node-set($messages1)/n0:ZHTR_LEAVE_SAL_ADVANCEResponse/E_LEAVEDATA/item/PERNR">
                        <PERNR>
                        <xsl:value-of select="msxsl:node-set($messages1)/n0:ZHTR_LEAVE_SAL_ADVANCEResponse/E_LEAVEDATA/item/PERNR"/>
                        </PERNR>
                        <AMOUNT>
                        <xsl:value-of select="msxsl:node-set($messages1)/n0:ZHTR_LEAVE_SAL_ADVANCEResponse/E_LEAVEDATA/item/AMOUNT"/>
                        </AMOUNT>
                    </xsl:if>
                </EmployeeTime>
            </xsl:for-each>     
        </EmployeeTime>
    </xsl:template>
</xsl:stylesheet>

The above XSLT gives me this error-

Error: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation

Can someone please help me with this error.

Regards,

Akash