on 2011 Nov 23 2:01 PM
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!!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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 <= $k">
<SPM>
<xsl:if test="$value1 > $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>
User | Count |
---|---|
70 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.