Skip to Content

Payload Transformation in CPI

Hello Community,

I want to transform the structure of a Payload like below using an XSLT Transformation or any other way.

Original Payload: (Many Root nodes with the same MessageHeader node)

<root>
<MessageHeader>
...
</MessageHeader>
<RequestMessage>
<MessageHeader/>
...
<RequestMessage>
</root>
<root>
<MessageHeader>
...
</MessageHeader>
<RequestMessage>
<MessageHeader/>
...
<RequestMessage>
</root>

Transformed Payload: One Root Node with One Message Header Node and Many RequestMessage Nodes

<root>
<MessageHeader>
...
</MessageHeader>
<RequestMessage>
<MessageHeader/>
...
<RequestMessage>
<RequestMessage>
<MessageHeader/>
...
<RequestMessage>
</root>

Could you help me please?

Thanks,

Nadir

Add a comment
10|10000 characters needed characters exceeded

Related questions

8 Answers

  • Posted on Aug 14 at 10:41 AM

    Hello Nadir,

    Could you please share correct XML with correct start and end tags ( you can put some dummy field name inside each nodes to make it clear )

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Sriprasad Shivaram Bhat,

      Thanks for your answer. Is it enough like below?

      Original Payload:

      <root>
      <MessageHeader>
              <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
              <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
      	<SenderParty>
      		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
      	</SenderParty>
      	<RecipientParty>
      		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
      	</RecipientParty>
      </MessageHeader>
      <RequestMessage>
      <MessageHeader/>
      <RequestMessageInformation>
      	<ID>FA163EBCE69E1EDAB7C020500C089126</ID>
      	<Name>New Name</Name>
      	<PriorityCode>3</PriorityCode>
      	<ProcessingDatePeriod>
      		<StartDate>2020-08-14</StartDate>
      		<EndDate>2020-08-21</EndDate>
      	</ProcessingDatePeriod>
      	<OriginTypeCode>003</OriginTypeCode>
      </RequestMessageInformation>
      </RequestMessage>
      </root>
      <root>
      <root>
      <MessageHeader>
              <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
              <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
      	<SenderParty>
      		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
      	</SenderParty>
      	<RecipientParty>
      		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
      	</RecipientParty>
      </MessageHeader>
      <RequestMessage>
      <MessageHeader/>
      <RequestMessageInformation>
      	<ID>FA163EBCE69E1EDAB7C020500C089127</ID>
      	<Name>New Name 2</Name>
      	<PriorityCode>3</PriorityCode>
      	<ProcessingDatePeriod>
      		<StartDate>2020-08-14</StartDate>
      		<EndDate>2020-08-21</EndDate>
      	</ProcessingDatePeriod>
      	<OriginTypeCode>003</OriginTypeCode>
      </RequestMessageInformation>
      </RequestMessage>
      </root>

      Transformed Payload:

      <root>
      <MessageHeader>
              <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
              <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
      	<SenderParty>
      		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
      	</SenderParty>
      	<RecipientParty>
      		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
      	</RecipientParty>
      </MessageHeader>
      <RequestMessage>
         <MessageHeader/>
         <RequestMessageInformation>
      	<ID>FA163EBCE69E1EDAB7C020500C089126</ID>
      	<Name>New Name</Name>
      	<PriorityCode>3</PriorityCode>
      	<ProcessingDatePeriod>
      		<StartDate>2020-08-14</StartDate>
      		<EndDate>2020-08-21</EndDate>
      	</ProcessingDatePeriod>
      	<OriginTypeCode>003</OriginTypeCode>
         </RequestMessageInformation>
      </RequestMessage>
      <RequestMessage>
         <MessageHeader/>
         <RequestMessageInformation>
      	<ID>FA163EBCE69E1EDAB7C020500C089127</ID>
      	<Name>New Name 2</Name>
      	<PriorityCode>3</PriorityCode>
      	<ProcessingDatePeriod>
      		<StartDate>2020-08-14</StartDate>
      		<EndDate>2020-08-21</EndDate>
      	</ProcessingDatePeriod>
      	<OriginTypeCode>003</OriginTypeCode>
         </RequestMessageInformation>
      </RequestMessage>
      </root>

      Regards,

      Nadir


  • Posted on Aug 14 at 11:27 AM

    Hello Nadir,

    First thing is you need to enclose above XML with root tag since its not a valid XML ( without root tag).

    For adding root add content modifier and in body use below.

    <MainRoot>
    ${in.body}
    </MainRoot>

    After that add below XSLT which would give you required output

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    	<xsl:strip-space elements="*"/>
    	<xsl:template match="@* | node()">
    		<xsl:copy>
    			<xsl:apply-templates select="@* | node()"/>
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="MainRoot">
    		<xsl:copy>
    			<xsl:for-each select="root">			
    				<xsl:apply-templates select="MessageHeader"/>
    				<xsl:copy-of select="RequestMessage"/>				
    			</xsl:for-each>
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="MessageHeader[ID = following::MessageHeader/ID]">
    		<xsl:copy-of select="MessageHeader"/>
    	</xsl:template>  
    </xsl:stylesheet>
    

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Sriprasad Shivaram Bhat,

      So I used your XSLT for the Code below:

      <MainRoot>
      <root>
      <MessageHeader>
              <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
              <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
      	<SenderParty>
      		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
      	</SenderParty>
      	<RecipientParty>
      		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
      	</RecipientParty>
      </MessageHeader>
      <RequestMessage>
      <MessageHeader/>
      <RequestMessageInformation>
      	<ID>FA163EBCE69E1EDAB7C020500C089126</ID>
      	<Name>New Name</Name>
      	<PriorityCode>3</PriorityCode>
      	<ProcessingDatePeriod>
      		<StartDate>2020-08-14</StartDate>
      		<EndDate>2020-08-21</EndDate>
      	</ProcessingDatePeriod>
      	<OriginTypeCode>003</OriginTypeCode>
      </RequestMessageInformation>
      </RequestMessage>
      </root>
      <root>
      <MessageHeader>
              <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
              <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
      	<SenderParty>
      		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
      	</SenderParty>
      	<RecipientParty>
      		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
      	</RecipientParty>
      </MessageHeader>
      <RequestMessage>
      <MessageHeader/>
      <RequestMessageInformation>
      	<ID>FA163EBCE69E1EDAB7C020500C089127</ID>
      	<Name>New Name 2</Name>
      	<PriorityCode>3</PriorityCode>
      	<ProcessingDatePeriod>
      		<StartDate>2020-08-14</StartDate>
      		<EndDate>2020-08-21</EndDate>
      	</ProcessingDatePeriod>
      	<OriginTypeCode>003</OriginTypeCode>
      </RequestMessageInformation>
      </RequestMessage>
      </root>
      </MainRoot>
      <br>

      And this is the result I got:

      <MainRoot>
         <RequestMessage>
            <MessageHeader/>
            <RequestMessageInformation>
               <ID>FA163EBCE69E1EDAB7C020500C089126</ID>
               <Name>New Name</Name>
               <PriorityCode>3</PriorityCode>
               <ProcessingDatePeriod>
                  <StartDate>2020-08-14</StartDate>
                  <EndDate>2020-08-21</EndDate>
               </ProcessingDatePeriod>
               <OriginTypeCode>003</OriginTypeCode>
            </RequestMessageInformation>
         </RequestMessage>
         <MessageHeader>
            <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
            <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
            <SenderParty>
               <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
            </SenderParty>
            <RecipientParty>
               <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
            </RecipientParty>
         </MessageHeader>
         <RequestMessage>
            <MessageHeader/>
            <RequestMessageInformation>
               <ID>FA163EBCE69E1EDAB7C020500C089127</ID>
               <Name>New Name 2</Name>
               <PriorityCode>3</PriorityCode>
               <ProcessingDatePeriod>
                  <StartDate>2020-08-14</StartDate>
                  <EndDate>2020-08-21</EndDate>
               </ProcessingDatePeriod>
               <OriginTypeCode>003</OriginTypeCode>
            </RequestMessageInformation>
         </RequestMessage>
      </MainRoot><br>

      There is no Root Node and The MessageHeader node should be before the RequestMessage nodes.

      Thanks for your help !

      Regards,

      Nadir

  • Posted on Aug 14 at 05:10 PM

    Hi Nadir,

    for the below input payload

    <root>
      <root>
        <MessageHeader>
          <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
          <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
          <SenderParty>
            <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
          </SenderParty>
          <RecipientParty>
            <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
          </RecipientParty>
        </MessageHeader>
        <RequestMessage>
          <MessageHeader/>
          <RequestMessageInformation>
            <ID>FA163EBCE69E1EDAB7C020500C089126</ID>
            <Name>New Name</Name>
            <PriorityCode>3</PriorityCode>
            <ProcessingDatePeriod>
              <StartDate>2020-08-14</StartDate>
              <EndDate>2020-08-21</EndDate>
            </ProcessingDatePeriod>
            <OriginTypeCode>003</OriginTypeCode>
          </RequestMessageInformation>
        </RequestMessage>
      </root>
      <root>
        <MessageHeader>
          <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
          <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
          <SenderParty>
            <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
          </SenderParty>
          <RecipientParty>
            <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
          </RecipientParty>
        </MessageHeader>
        <RequestMessage>
          <MessageHeader/>
          <RequestMessageInformation>
            <ID>FA163EBCE69E1EDAB7C020500C089127</ID>
            <Name>New Name 2</Name>
            <PriorityCode>3</PriorityCode>
            <ProcessingDatePeriod>
              <StartDate>2020-08-14</StartDate>
              <EndDate>2020-08-21</EndDate>
            </ProcessingDatePeriod>
            <OriginTypeCode>003</OriginTypeCode>
          </RequestMessageInformation>
        </RequestMessage>
      </root>
    </root>
    

    use the below XSLT

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:template match="/">
          <root>
             <root>
                <MessageHeader>
                   <ID>
                      <xsl:value-of select="/root/root/MessageHeader[1]/ID"/>
                   </ID>
                   <CreationDateTime>
                      <xsl:value-of select="/root/root/MessageHeader[1]/CreationDateTime"/>
                   </CreationDateTime>
                   <SenderParty>
                      <InternalID>
                         <xsl:if test="/root/root/MessageHeader[1]/SenderParty/InternalID/@schemeID">
                            <xsl:attribute name="schemeID">
                               <xsl:value-of select="/root/root/MessageHeader[1]/SenderParty/InternalID/@schemeID"/>
                            </xsl:attribute>
                         </xsl:if>
                         <xsl:if test="/root/root/MessageHeader[1]/SenderParty/InternalID/@schemeAgencyID">
                            <xsl:attribute name="schemeAgencyID">
                               <xsl:value-of select="/root/root/MessageHeader[1]/SenderParty/InternalID/@schemeAgencyID"/>
                            </xsl:attribute>
                         </xsl:if>
                         <xsl:value-of select="/root/root/MessageHeader[1]/SenderParty/InternalID"/>
                      </InternalID>
                   </SenderParty>
                   <RecipientParty>
                      <InternalID>
                         <xsl:if test="/root/root/MessageHeader[1]/RecipientParty/InternalID/@schemeID">
                            <xsl:attribute name="schemeID">
                               <xsl:value-of select="/root/root/MessageHeader[1]/RecipientParty/InternalID/@schemeID"/>
                            </xsl:attribute>
                         </xsl:if>
                         <xsl:if test="/root/root/MessageHeader[1]/RecipientParty/InternalID/@schemeAgencyID">
                            <xsl:attribute name="schemeAgencyID">
                               <xsl:value-of select="/root/root/MessageHeader[1]/RecipientParty/InternalID/@schemeAgencyID"/>
                            </xsl:attribute>
                         </xsl:if>
                         <xsl:value-of select="/root/root/MessageHeader[1]/RecipientParty/InternalID"/>
                      </InternalID>
                   </RecipientParty>
                </MessageHeader>
                <xsl:for-each select="/root/root/RequestMessage">
                   <RequestMessage>
                      <MessageHeader>
                         <xsl:value-of select="MessageHeader"/>
                      </MessageHeader>
                      <RequestMessageInformation>
                         <ID>
                            <xsl:value-of select="RequestMessageInformation/ID"/>
                         </ID>
                         <Name>
                            <xsl:value-of select="RequestMessageInformation/Name"/>
                         </Name>
                         <PriorityCode>
                            <xsl:value-of select="RequestMessageInformation/PriorityCode"/>
                         </PriorityCode>
                         <ProcessingDatePeriod>
                            <StartDate>
                               <xsl:value-of select="RequestMessageInformation/ProcessingDatePeriod/StartDate"/>
                            </StartDate>
                            <EndDate>
                               <xsl:value-of select="RequestMessageInformation/ProcessingDatePeriod/EndDate"/>
                            </EndDate>
                         </ProcessingDatePeriod>
                         <OriginTypeCode>
                            <xsl:value-of select="RequestMessageInformation/OriginTypeCode"/>
                         </OriginTypeCode>
                      </RequestMessageInformation>
                   </RequestMessage>
                </xsl:for-each>
             </root>
          </root>
       </xsl:template>
    </xsl:stylesheet>
    
    
    

    to get below output:

    <root>
       <root>
          <MessageHeader>
             <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
             <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
             <SenderParty>
                <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
             </SenderParty>
             <RecipientParty>
                <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
             </RecipientParty>
          </MessageHeader>
          <RequestMessage>
             <MessageHeader/>
             <RequestMessageInformation>
                <ID>FA163EBCE69E1EDAB7C020500C089126</ID>
                <Name>New Name</Name>
                <PriorityCode>3</PriorityCode>
                <ProcessingDatePeriod>
                   <StartDate>2020-08-14</StartDate>
                   <EndDate>2020-08-21</EndDate>
                </ProcessingDatePeriod>
                <OriginTypeCode>003</OriginTypeCode>
             </RequestMessageInformation>
          </RequestMessage>
          <RequestMessage>
             <MessageHeader/>
             <RequestMessageInformation>
                <ID>FA163EBCE69E1EDAB7C020500C089127</ID>
                <Name>New Name 2</Name>
                <PriorityCode>3</PriorityCode>
                <ProcessingDatePeriod>
                   <StartDate>2020-08-14</StartDate>
                   <EndDate>2020-08-21</EndDate>
                </ProcessingDatePeriod>
                <OriginTypeCode>003</OriginTypeCode>
             </RequestMessageInformation>
          </RequestMessage>
       </root>
    </root>
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 17 at 02:30 AM

    Hello Nadir,

    Below should work and I would suggest you to tweak to code & try out different possibilities.

    <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns2="http://www.w3.org/1999/XSL/Transform" xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge"  xmlns:ns1="http://sap.com/xi/SAPGlobal20/Global" exclude-result-prefixes="multimap ns1">
    	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    	<xsl:strip-space elements="*"/>
    	<xsl:template match="/|comment()|processing-instruction()">
    		<xsl:copy>
    			<xsl:apply-templates />
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="*">
    		<xsl:element name="{local-name()}">
    			<xsl:apply-templates select="@*|node()" />
    		</xsl:element>
    	</xsl:template>
    	<xsl:template match="@*">
    		<xsl:attribute name="{local-name()}">
    			<xsl:value-of select="." />
    		</xsl:attribute>
    	</xsl:template>
    	<xsl:template match="multimap:Messages/multimap:Message1" >
    		<Root>
    			<xsl:for-each-group select="ns1:LeanLeadReplicationBulkReplicateRequest" group-by="MessageHeader/ID">
    				<Records>
    					<xsl:for-each select="current-group()">
    						<xsl:apply-templates select="MessageHeader"/>
    						<xsl:copy-of select="LeanLeadReplicateRequestMessage"/>
    					</xsl:for-each>
    				</Records>
    			</xsl:for-each-group>
    		</Root>
    	</xsl:template>
    	<xsl:template match="MessageHeader[ID = following::MessageHeader/ID]">
    		<xsl:copy-of select="MessageHeader"/>
    	</xsl:template>
    	<xsl:template match="multimap:Messages">        
    		<xsl:apply-templates />        
    	</xsl:template>
    </xsl:stylesheet>
    

    Regards,
    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Sriprasad Shivaram Bhat

      Thanks for your answer, I have no idea how to work on an XSLT.

      It did not work, same as my above answer.

      Please see my comment from yesterday, it is just a position matter for now:

      Transformed Payload by your code:

      <root>
      <RequestMessage>
               <MessageHeader/>
               <RequestMessageInformation>
               </RequestMessageInformation>
      </RequestMessage>
      <MessageHeader>
      </MessageHeader>
      <RequestMessage>
               <MessageHeader/>
               <RequestMessageInformation>
               </RequestMessageInformation>
      </RequestMessage>
      </root>
      

      Expected Payload:

      <root>
      <MessageHeader>
      </MessageHeader>
      <RequestMessage>
               <MessageHeader/>
               <RequestMessageInformation>
               </RequestMessageInformation>
      </RequestMessage>
      <RequestMessage>
               <MessageHeader/>
               <RequestMessageInformation>
               </RequestMessageInformation>
      </RequestMessage>
      </root>

      Regards,

      Nadir

  • Posted on Aug 17 at 08:14 AM

    Dear Nadir,

    I am completely confused with your Input Structure and Output structure.As per your earlier thread input structure was having multimap:Message tag and whatever you have pasted now has nothing.Please share the correct input and output structure you are looking for to get correct response from community.

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 17 at 08:23 AM

    Hi Sriprasad Shivaram Bhat

    Sorry for the confusion. To simplify, please take into account the situation below:

    Incoming Payload:

    <MainRoot>
    <root>
    <MessageHeader>
            <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
            <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
    	<SenderParty>
    		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
    	</SenderParty>
    	<RecipientParty>
    		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
    	</RecipientParty>
    </MessageHeader>
    <RequestMessage>
    <MessageHeader/>
    <RequestMessageInformation>
    	<ID>FA163EBCE69E1EDAB7C020500C089126</ID>
    	<Name>New Name</Name>
    	<PriorityCode>3</PriorityCode>
    	<ProcessingDatePeriod>
    		<StartDate>2020-08-14</StartDate>
    		<EndDate>2020-08-21</EndDate>
    	</ProcessingDatePeriod>
    	<OriginTypeCode>003</OriginTypeCode>
    </RequestMessageInformation>
    </RequestMessage>
    </root>
    <root>
    <MessageHeader>
            <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
            <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
    	<SenderParty>
    		<InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
    	</SenderParty>
    	<RecipientParty>
    		<InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
    	</RecipientParty>
    </MessageHeader>
    <RequestMessage>
    <MessageHeader/>
    <RequestMessageInformation>
    	<ID>FA163EBCE69E1EDAB7C020500C089127</ID>
    	<Name>New Name 2</Name>
    	<PriorityCode>3</PriorityCode>
    	<ProcessingDatePeriod>
    		<StartDate>2020-08-14</StartDate>
    		<EndDate>2020-08-21</EndDate>
    	</ProcessingDatePeriod>
    	<OriginTypeCode>003</OriginTypeCode>
    </RequestMessageInformation>
    </RequestMessage>
    </root>
    </MainRoot>

    Transformed Payload by your first XSLT:

    <MainRoot>
       <RequestMessage>
          <MessageHeader/>
          <RequestMessageInformation>
             <ID>FA163EBCE69E1EDAB7C020500C089126</ID>
             <Name>New Name</Name>
             <PriorityCode>3</PriorityCode>
             <ProcessingDatePeriod>
                <StartDate>2020-08-14</StartDate>
                <EndDate>2020-08-21</EndDate>
             </ProcessingDatePeriod>
             <OriginTypeCode>003</OriginTypeCode>
          </RequestMessageInformation>
       </RequestMessage>
       <MessageHeader>
          <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
          <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
          <SenderParty>
             <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
          </SenderParty>
          <RecipientParty>
             <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
          </RecipientParty>
       </MessageHeader>
       <RequestMessage>
          <MessageHeader/>
          <RequestMessageInformation>
             <ID>FA163EBCE69E1EDAB7C020500C089127</ID>
             <Name>New Name 2</Name>
             <PriorityCode>3</PriorityCode>
             <ProcessingDatePeriod>
                <StartDate>2020-08-14</StartDate>
                <EndDate>2020-08-21</EndDate>
             </ProcessingDatePeriod>
             <OriginTypeCode>003</OriginTypeCode>
          </RequestMessageInformation>
       </RequestMessage>
    </MainRoot>

    Expected Payload:

    <root>
       <MessageHeader>
          <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
          <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
          <SenderParty>
             <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
          </SenderParty>
          <RecipientParty>
             <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
          </RecipientParty>
       </MessageHeader>
       <RequestMessage>
          <MessageHeader/>
          <RequestMessageInformation>
             <ID>FA163EBCE69E1EDAB7C020500C089126</ID>
             <Name>New Name</Name>
             <PriorityCode>3</PriorityCode>
             <ProcessingDatePeriod>
                <StartDate>2020-08-14</StartDate>
                <EndDate>2020-08-21</EndDate>
             </ProcessingDatePeriod>
             <OriginTypeCode>003</OriginTypeCode>
          </RequestMessageInformation>
       </RequestMessage>
       <RequestMessage>
          <MessageHeader/>
          <RequestMessageInformation>
             <ID>FA163EBCE69E1EDAB7C020500C089127</ID>
             <Name>New Name 2</Name>
             <PriorityCode>3</PriorityCode>
             <ProcessingDatePeriod>
                <StartDate>2020-08-14</StartDate>
                <EndDate>2020-08-21</EndDate>
             </ProcessingDatePeriod>
             <OriginTypeCode>003</OriginTypeCode>
          </RequestMessageInformation>
       </RequestMessage>
    </root>

    I hope it is more clear.

    Thanks a lot.

    Regards,

    Nadir

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 17 at 08:34 AM

    Hello Nadir,

    Below should work for you.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    	<xsl:strip-space elements="*"/>
    	<xsl:template match="@* | node()">
    		<xsl:copy>
    			<xsl:apply-templates select="@* | node()"/>
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="MainRoot">
              <root>
    		<xsl:for-each select="root">						
    				<xsl:apply-templates select="MessageHeader"/>
    				<xsl:copy-of select="RequestMessage"/>						
    		</xsl:for-each>
             </root>
    	</xsl:template>
    	<xsl:template match="MessageHeader[ID = following::MessageHeader/ID]">
    		<xsl:copy-of select="MessageHeader"/>
    	</xsl:template>  
    </xsl:stylesheet>
    

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Sriprasad Shivaram Bhat

      This is what i am getting from your XSLT:

      <root>
         <RequestMessage>
            <MessageHeader/>
            <RequestMessageInformation>
               <ID>FA163EBCE69E1EDAB7C020500C089126</ID>
               <Name>New Name</Name>
               <PriorityCode>3</PriorityCode>
               <ProcessingDatePeriod>
                  <StartDate>2020-08-14</StartDate>
                  <EndDate>2020-08-21</EndDate>
               </ProcessingDatePeriod>
               <OriginTypeCode>003</OriginTypeCode>
            </RequestMessageInformation>
         </RequestMessage>
         <MessageHeader>
            <ID>FA163EBCE69E1EDAB7C01B84C65C7123</ID>
            <CreationDateTime>2020-08-14T07:36:27.072333Z</CreationDateTime>
            <SenderParty>
               <InternalID schemeID="LocalSystemID" schemeAgencyID="310">SENDER1</InternalID>
            </SenderParty>
            <RecipientParty>
               <InternalID schemeID="BusinessSystemID" schemeAgencyID="310">RECEIVER1</InternalID>
            </RecipientParty>
         </MessageHeader>
         <RequestMessage>
            <MessageHeader/>
            <RequestMessageInformation>
               <ID>FA163EBCE69E1EDAB7C020500C089127</ID>
               <Name>New Name 2</Name>
               <PriorityCode>3</PriorityCode>
               <ProcessingDatePeriod>
                  <StartDate>2020-08-14</StartDate>
                  <EndDate>2020-08-21</EndDate>
               </ProcessingDatePeriod>
               <OriginTypeCode>003</OriginTypeCode>
            </RequestMessageInformation>
         </RequestMessage>
      </root>

      The root/MessageHeader node should be before all RequestMessage Nodes.

      Thanks !

      Regards,

      Nadir

  • Posted on Aug 17 at 04:46 PM

    Hello everyone,

    Thanks for your help !

    I finally did it with the XSLT below:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="MainRoot">
    <root>
    <xsl:copy-of select="root[1]/MessageHeader"/>
    <xsl:for-each select="root">
    <xsl:copy-of select="RequestMessage"/>
    </xsl:for-each>
    </root>
    </xsl:template>
    </xsl:stylesheet>
    
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.