cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT help required

Former Member
0 Kudos

I am stuck with XSLT mapping for split message(Dont want to use graphical),. I want to generate new message type based upon the unique reference id.

Sharing my input and output smaples, please provide me clues on how to make the split-by-value with value change in XSLT for the field where target node will be the message type where as the source field is ReferenceID.(for one unique reference id - one message type to be created).

Source payload

---------------------------------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<MT_Src>

    <row>

        <ReferenceID>00002001</ReferenceID>

        <ReferenceDate>20131220</ReferenceDate>

       

    </row>

    <row>

        <ReferenceID>00002001</ReferenceID>

        <ReferenceDate>20131220</ReferenceDate>

       

    </row>

    <row>

        <ReferenceID>00002001</ReferenceID>

        <ReferenceDate>20131220</ReferenceDate>

            </row>

    <row>

        <ReferenceID>00002001</ReferenceID>

        <ReferenceDate>20131220</ReferenceDate>

       

    </row>

    <row>

        <ReferenceID>00002001</ReferenceID>

        <ReferenceDate>20131220</ReferenceDate>

       

    </row>

    <row>

        <ReferenceID>00002001</ReferenceID>

        <ReferenceDate>20131220</ReferenceDate>

       

    </row>

</MT_Src>

------------------------------------------------------------------------------------------------------------------------------

Desired output

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">

   <ns0:Message1>

      <ns1:MT_Tgt xmlns:ns1="TargetNamespace">

         <HeaderRecord>

           <field1>constant</field1>

            <StartingDate>fielld in source is reference date</StartingDate>

             <ReferenceID>00002001</ReferenceID>

         </HeaderRecord>

         <DetailRecord>

<field2>constant</field2>

            <ReferenceID>00002001</ReferenceID>

            <DocumentDate>fielld in source is reference date</DocumentDate>

             </DetailRecord>

         <DetailRecord>

            <ReferenceID>00002001</ReferenceID>

            <DocumentDate>fielld in source is reference date</DocumentDate>

              </DetailRecord>

         <TrailerRecord>

<field2>constant</field2>

            <EndingDate>2fielld in source is reference date</EndingDate>

              <ReferenceID>00002001</ReferenceID>

         </TrailerRecord>

      </ns1:MT_Tgt>

      <ns1:MT_Tgt xmlns:ns1="TargetNamespace">

         <HeaderRecord>

  <field1>constant</field1>

            <StartingDate>fielld in source is reference date</StartingDate>

            <ReferenceID>00002002</ReferenceID>

         </HeaderRecord>

         <DetailRecord>

            <ReferenceID>00002002</ReferenceID>

            <DocumentDate>fielld in source is reference date</DocumentDate>

          

         </DetailRecord>

         <TrailerRecord>

<field2>constant</field2>

            <EndingDate>fielld in source is reference date</EndingDate>

            <ReferenceID>00002002</ReferenceID>

         </TrailerRecord>

      </ns1:MT_Tgt>

   </ns0:Message1>

</ns0:Messages>

-------------------------------------------------------------------------------------------------------------------------

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Check this:


<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:split="http://sap.com/xi/XI/SplitAndMerge" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:template match="/">

      <split:Messages>

         <Message1>

            <xsl:for-each select="//row">

               <xsl:sort select="ReferenceID"/>

               <xsl:if test="not(ReferenceID = preceding-sibling::row/ReferenceID)">

                  <MT_Tgt>

                     <HeaderRecord>

                        <ReferenceID>

                           <xsl:value-of select="ReferenceID"/>

                        </ReferenceID>

                        <field1>constant</field1>

                        <StartingDate>

                           <xsl:value-of select="ReferenceDate"/>

                        </StartingDate>

                     </HeaderRecord>

                     <xsl:call-template name="process_items">

                        <xsl:with-param name="items" select="ReferenceID"/>

                     </xsl:call-template>

                  </MT_Tgt>

               </xsl:if>

            </xsl:for-each>

         </Message1>

      </split:Messages>

   </xsl:template>

   <xsl:template name="process_items">

      <xsl:param name="items"/>

      <xsl:for-each select="//row">

         <xsl:if test="($items = ReferenceID)">

            <DetailRecord>

               <field2>constant</field2>

               <ReferenceID>

                  <xsl:value-of select="ReferenceID"/>

               </ReferenceID>

               <DocumentDate>

                  <xsl:value-of select="ReferenceDate"/>

               </DocumentDate>

            </DetailRecord>

         </xsl:if>

      </xsl:for-each>

   </xsl:template>

</xsl:stylesheet>

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

Thanks alot for your code, I almost done with my work but I have some other issues, will get back to you on them. and I will give you full points ASAP. 🙂

Prasad.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Prasad,

You can achieve this with multimapping by using the features of graphical mapping which is available with PI itself.

Is there any specific requirement from client to use xslt mapping?

Regards

Raj

Former Member
0 Kudos

Raja, yes we dont want to use the graphical mapping here so either java mapping / xslt for split mapping we want.

Former Member
0 Kudos

Hi Prasad,

what I understand is you are trying to do a field based split (Multi mapping in XSLT)

try this

<?xml version='1.0' ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:split="http://sap.com/xi/XI/SplitAndMerge" exclude-result-prefixes="<if any xtra NS's>">

<xsl:template match="/">

  <split:Messages>

   <Message1>

    <a:MT_Tgt>

     <xsl:for-each select="//MT_Src/ReferenceID">

      <HeaderRecord>

      <!-- <ur mapping>-->

      </HeaderRecord>

     </xsl:for-each>

    </a:MT_Tgt>

   </Message1>

  </split:Messages>

</xsl:template>

</xsl:stylesheet>

let me know if any issues.

Thanks,

Aman Gupta

Former Member
0 Kudos

Hi Aman,

your code returns all the reference ids, but as per my requirement it has to create the target message type based on reference id only one time for each value(i.e. it is like split by value(value change) and then collapse context)

Thanks.

Former Member
0 Kudos

Hi Prasad,

try this, you might have to change the stylesheet a little

Thanks,

Aman Gupta