Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • GeetG 11 posts 91 karma points
    Oct 20, 2020 @ 08:57
    GeetG
    0

    XSLT to remove namespaces and rename tags.

    Hi All,

    I'm new to this forum hope I get help here. Here is my below Input request message.

    <n0:EmployeeBulkReplicationRequest xmlns:n0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:L52:/1SAI/TASAFC37ED2487AA8DA0EB9:804">
       <MessageHeader>
          <ID>00B</ID>
          <UUID>001b</UUID>
          <CreationDateTime>2020-10-19T13:14:19.896485Z</CreationDateTime>
          <SenderBusinessSystemID>0</SenderBusinessSystemID>
          <RecipientBusinessSystemID>DUMMY</RecipientBusinessSystemID>
          <SenderParty>
             <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">0</InternalID>
          </SenderParty>
          <RecipientParty>
             <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">DUMMY</InternalID>
          </RecipientParty>
       </MessageHeader>
       <EmployeesReplicationRequest>
          <MessageHeader>
             <ID>00</ID>
             <UUID>00</UUID>
          </MessageHeader>
          <Employee ActionCode="04" EmployeeProviderSkillsCompleteTransmissionIndicator="true">
             <EmployeeID>70</EmployeeID>
             <BusinessPartnerID>80</BusinessPartnerID>
             <EmployeeUUID>00</EmployeeUUID>
             <BusinessPartnerUUID>00</BusinessPartnerUUID>
             <Common actionCode="04">
                <Name>
                   <FormOfAddressCode>0002</FormOfAddressCode>
                   <GivenName>OName1</GivenName>
                   <FamilyName>OSurnameTest2</FamilyName>
                </Name>
                <MaritalStatusCode>1</MaritalStatusCode>
                <n1:zPersonalID xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">12</n1:zPersonalID>
                <n2:zTccBranchType xmlns:n2="http://sap.com/xi/AP/CustomerExtension/BYD/A3YO6">101</n2:zTccBranchType>
                <n1:zRelMainPartner xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">10</n1:zRelMainPartner>
                <n1:zRelLocProfile xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">1000471</n1:zRelLocProfile>
                <n1:zzMSISDN xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">12345678</n1:zzMSISDN>
                <n1:zUplDocReqTaff xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">true</n1:zUplDocReqTaff>
                <n1:zUserId xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">OR5</n1:zUserId>
                <n1:zHireDate xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">2020-10-01</n1:zHireDate>
                <n1:zTerminationDate xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">2023-10-05</n1:zTerminationDate>
                <n1:zBENEFICIARY_BIC xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">QC</n1:zBENEFICIARY_BIC>
                <n1:zBENEFICIARY_IBAN xmlns:n1="http://0007408881-one-off.sap.com/YLD22ZF5Y_">TR34</n1:zBENEFICIARY_IBAN>
                <n2:zTafeelyUserRole xmlns:n2="http://sap.com/xi/AP/CustomerExtension/BYD/A3YO6">Mob</n2:zTafeelyUserRole>
             </Common>
             <ObjectIdentifierMapping ActionCode="04"/>
             <EmployeeType actionCode="04">
                <ValidityPeriod>
                   <StartDate>0001-01-01</StartDate>
                   <EndDate>9999-12-31</EndDate>
                </ValidityPeriod>
             </EmployeeType>
             <WorkplaceAddress actionCode="04">
                <PhoneNumberDescription>+974</PhoneNumberDescription>
                <EmailURI>[email protected]</EmailURI>
                <MobilePhoneNumberDescription>+974 </MobilePhoneNumberDescription>
                <HouseID>12</HouseID>
                <StreetName>Streetname</StreetName>
                <CityName>Ridadh</CityName>
                <RegionCode>01</RegionCode>
                <CountryCode>SA</CountryCode>
                <StreetPostalCode>12345</StreetPostalCode>
             </WorkplaceAddress>
          </Employee>
       </EmployeesReplicationRequest>
    </n0:EmployeeBulkReplicationRequest>
    

    Here is my XSLT:

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:n0="http://sap.com/xi/SAPGlobal20/Global"
    exclude-result-prefixes="n0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="n0:EmployeeBulkReplicationRequest">
        <Profiles>
            <xsl:apply-templates select="MessageHeader"/>
        </Profiles>
    </xsl:template>
    <xsl:template match="*">
        <xsl:element name="{name()}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="EmployeeBulkReplicationRequest/">
        <xsl:copy>
          <xsl:apply-templates select ="MessageHeader/>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    

    My Expected Output:

    <Profiles>
       <MessageHeader>
          <ID>00B</ID>
          <UUID>001b</UUID>
          <CreationDateTime>2020-10-19T13:14:19.896485Z</CreationDateTime>
          <SenderBusinessSystemID>0</SenderBusinessSystemID>
          <RecipientBusinessSystemID>DUMMY</RecipientBusinessSystemID>
          <SenderParty>
             <InternalID>0Q</InternalID>
          </SenderParty>
          <RecipientParty>
             <InternalID>DUMMY</InternalID>
          </RecipientParty>
       </MessageHeader>
    </Profiles>
    <Profiles_info>
          <MessageHeader>
             <ID>00B</ID>
             <UUID>001b</UUID>
          </MessageHeader>
          <Employee ActionCode="04" EmployeeProviderSkillsCompleteTransmissionIndicator="true">
             <EmployeeID>70</EmployeeID>
             <BusinessPartnerID>80</BusinessPartnerID>
             <EmployeeUUID>00</EmployeeUUID>
             <BusinessPartnerUUID>00</BusinessPartnerUUID>
             <Common actionCode="04">
                <Name>
                   <FormOfAddressCode>0002</FormOfAddressCode>
                   <GivenName>OName1</GivenName>
                   <FamilyName>O</FamilyName>
                </Name>
                  <zPersonalID >12314567</zPersonalID>
            <zTccBranchType >101</zTccBranchType>
            <zRelMainPartner>1000419</zRelMainPartner>
            <zRelLocProfile>1000471</zRelLocProfile>
            <zzMSISDN >12345678</zzMSISDN>
            <zUplDocReqTaff >true</zUplDocReqTaff>
            <zUserId>O5</zUserId>
            <zHireDate>2020-10-01</zHireDate>
            <zTerminationDate >2023-10-05</zTerminationDate>
            <zBENEFICIARY_BIC>QIC</zBENEFICIARY_BIC>
            <zBENEFICIARY_IBAN>TR34</zBENEFICIARY_IBAN>
            <zTafeelyUserRole >Mob</zTafeelyUserRole>
         </Common>
             </Common>
             <ObjectIdentifierMapping ActionCode="04"/>
             <EmployeeType actionCode="04">
                <ValidityPeriod>
                   <StartDate>0001-01-01</StartDate>
                   <EndDate>9999-12-31</EndDate>
                </ValidityPeriod>
             </EmployeeType>
             <WorkplaceAddress actionCode="04">
                <PhoneNumberDescription>+974</PhoneNumberDescription>
                <EmailURI>[email protected]</EmailURI>
                <MobilePhoneNumberDescription>+974 </MobilePhoneNumberDescription>
                <HouseID>12</HouseID>
                <StreetName>Streetname</StreetName>
                <CityName>Rid</CityName>
                <RegionCode>01</RegionCode>
                <CountryCode>SA</CountryCode>
                <StreetPostalCode>12345</StreetPostalCode>
             </WorkplaceAddress>
          </Employee>
       </Profiles_info>
       </Profiles>
    

    Can someone please help me on this. Values in my input and output will differ in my payloads.

  • Alianna Flynn 1 post 91 karma points
    Oct 20, 2020 @ 12:56
    Alianna Flynn
    100

    Your output isn't valid XML, you're closing the 'Profiles' tag twice- I'm inclined to assume the first time it's closed is the erroneous one, otherwise your output will have two root elements, which also isn't valid XML.

    I think this is close to what you're looking for:

    <xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:n0="http://sap.com/xi/SAPGlobal20/Global"
       exclude-result-prefixes="n0">
    
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="n0:EmployeeBulkReplicationRequest">
        <Profiles>
          <xsl:apply-templates select="*"/>
        </Profiles>
      </xsl:template>
    
      <!-- MessageHeader and any descendents, output without attributes. -->
      <xsl:template match="MessageHeader | MessageHeader//*">
        <xsl:element name="{local-name()}">
          <xsl:apply-templates/>
        </xsl:element>
      </xsl:template>
    
      <!-- Any descendent elements of EmployeesReplicationRequest, output WITH attributes. -->
      <xsl:template match="EmployeesReplicationRequest//*">
        <xsl:element name="{local-name()}">
          <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
      </xsl:template>
    
      <!-- Any descendent attributes of EmployeesReplicationRequest, output 'as-is' -->
      <xsl:template match="EmployeesReplicationRequest//@*">
        <xsl:copy-of select="."/>
      </xsl:template>
    
      <xsl:template match="EmployeesReplicationRequest">
        <Profiles_info>
          <xsl:apply-templates select="*"/>
        </Profiles_info>
      </xsl:template>
    </xsl:stylesheet>
    
  • GeetG 11 posts 91 karma points
    Oct 22, 2020 @ 07:04
    GeetG
    0

    Thankyou so much. It worked as expected.

Please Sign in or register to post replies

Write your reply to:

Draft