cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Requirement

Former Member
0 Kudos
77

Hi All,

I am trying to achieve one XSLT mapping requirement for the below source structure.The values under "Level" and "Parent" source field dynamically determine the target structure node "SPM" and its hierachy on the target side.


<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_Test xmlns:ns0="http://test">
   <Header>
      <Name>xx</Name>
      <Age>12</Age>
      <Item>
         <Level>1</Level>
         <Parent>0</Parent>
         <Company>A</Company>
      </Item>
      <Item>
         <Level>2</Level>
         <Parent>1</Parent>
         <Company>B</Company>
      </Item>
      <Item>
         <Level>3</Level>
         <Parent>2</Parent>
         <Company>C</Company>
      </Item>
      <Item>
         <Level>2</Level>
         <Parent>1</Parent>
         <Company>D</Company>
      </Item>
      <Item>
         <Level>3</Level>
         <Parent>2</Parent>
         <Company>E</Company>
      </Item>
      <Item>
         <Level>3</Level>
         <Parent>2</Parent>
         <Company>F</Company>
      </Item>
   </Header>
</ns0:MT_Test>

Target:


<?xml version="1.0" encoding="UTF-8"?>
<MT_Target xmlns:ns0="http://test">
   <Records>
      <Name>xx</Name>
      <Age>12</Age>
      <SPM>
         <Level>1</Level>
         <Parent>0</Parent>
         <Company>A</Company>
              <SPM>
            <Level>2</Level>
            <Parent>1</Parent>
            <Company>B</Company>
                   <SPM>
                   <Level>3</Level>
                   <Parent>2</Parent>
                   <Company>C</Company>
                    </SPM>
             </SPM>
               <SPM>
                  <Level>2</Level>
                  <Parent>1</Parent>
                  <Company>D</Company>
                  <SPM>
                     <Level>3</Level>
                     <Parent>2</Parent>
                     <Company>E</Company>
                  </SPM>
                     <SPM>
                     <Level>3</Level>
                     <Parent>2</Parent>
                     <Company>F</Company>
                </SPM> 
         </SPM>
      </SPM>
   </Records>
</MT_Target>

Please help.

Thanks!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

if the number of hierarchy levels is known, you can also use message mapping and map to a recursive structure of a certain predefined depth. Refer to [Structure Overview in Message Mappings on SAP help|http://help.sap.com/saphelp_nwpi71/helpdata/en/e3/92be7c6cd34fd485c967144e302fb6/content.htm] on how to use recursive structures:

...It is possible to map these elements in the mapping editor in a rudimentary fashion by using the context menu to expand a specific number of subnodes and then use them in target-field mappings...

If the number of hierarchy levels is unknown, use XSL mapping. You have to create a template for Item and call it recursively for all lower level Items in order to create the hierarchy.

Regards, Martin

Former Member
0 Kudos

Hi,

Thanks for your reply.

we want to go with xslt mapping because the hierarchy levels are unbounded. Request you to please provide me the xslt mapping for this requirement.

Thanks!!

Former Member
0 Kudos

Hi All,

Any inputs?

Former Member
0 Kudos

Hi Anu,

I am trying to set up the script.

but until now, not sucefully.

Look to this, and try make alterations in script.

Hope this helps you.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://test">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

<xsl:template match="/">
	<MT_Target xmlns:ns0="http://test">
<Records>
<Name>
<xsl:value-of select="ns1:MT_Test/Header/Name" /> 
</Name>
<Age>
<xsl:value-of select="ns1:MT_Test/Header/Age" /> 
</Age>
<xsl:for-each select="ns1:MT_Test/Header/Item">
<SPM>
  <xsl:copy-of select="node()" /> 
   </SPM> 
</xsl:for-each>
<xsl:for-each select="ns1:MT_Test/Header/Item">

</xsl:for-each>
</Records>
</MT_Target>
	</xsl:template>
</xsl:stylesheet>

att.

Former Member
0 Kudos

Hi,

I have created the below xslt but it is not resulting the expected output. All the SPM's are getting created under each other(shown below) using below code. Please help!!


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:ns0="http://test" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
      <MT_Target>
         <Records>
            <Name>
               <xsl:value-of select="ns0:MT_Test/SPL_Header/Name"/>
            </Name>
            <Age>
               <xsl:value-of select="ns0:MT_Test/SPL_Header/Age"/>
            </Age>
            <xsl:variable name="Max_No">
               <xsl:value-of select="count(//Item)"/>
            </xsl:variable>
                       <xsl:call-template name="Loop">
               <xsl:with-param name="i">1</xsl:with-param>
               <xsl:with-param name="k" select="$Max_No"/>
               <xsl:with-param name="j" select="0"/>
            </xsl:call-template>
         </Records>
      </MT_Target>
   </xsl:template>
   <xsl:template name="Loop">
      <xsl:param name="i"/>
      <xsl:param name="k"/>
      <xsl:param name="j"/>
 <xsl:variable name="value1">
        <xsl:value-of select="//Item[$i]/Level"/>
        </xsl:variable>
<xsl:if test="$i &lt;= $k"> 
  <SPM>
        <xsl:if test="$value1 &gt; $j">
            <Level>
           <xsl:value-of select="//Item[$i]/Level"/>
            </Level>
            <Parent>
              <xsl:value-of select="//Item[$i]/Parent"/>
            </Parent>
            <Company>
            <xsl:value-of select="//Item[$i]/Company"/>
            </Company>           
    <xsl:call-template name="Loop">
                  <xsl:with-param name="i">
                     <xsl:value-of select="$i + 1"/>
                  </xsl:with-param>
                  <xsl:with-param name="j">
                     <xsl:value-of select="$value1"/>
                  </xsl:with-param>
                  <xsl:with-param name="k">
                     <xsl:value-of select="$k"/>
                  </xsl:with-param>
               </xsl:call-template>
    </xsl:if>
</SPM>
</xsl:if>
/xsl:template>
</xsl:stylesheet>

XSLT output (which is not correctt) :



<?xml version="1.0" encoding="UTF-8"?>
<MT_Target xmlns:ns0="http://test">
   <Records>
      <Name>xx</Name>
      <Age>12</Age>
      <SPM>
         <Level>1</Level>
         <Parent>0</Parent>
         <Company>A</Company>
         <SPM>
            <Level>2</Level>
            <Parent>1</Parent>
            <Company>B</Company>
            <SPM>
               <Level>3</Level>
               <Parent>2</Parent>
               <Company>C</Company>
               <SPM/>
            </SPM>
         </SPM>
      </SPM>
   </Records>
</MT_Target>

Former Member
0 Kudos

i am not sure whether u r still struggling to solve ur mapping req or not??

but recently i have a requirement quite similar as urs (and able to crack the code also) so in case u are still seeking for help please let me know...

Answers (0)