on 06-27-2013 5:23 AM
Hi Guys,
I have a requirement to change the rootnode and namespace of the structure using XSLT mapping.I am very new to XSLT mapping,i have gone through some block and implemeted the code as per the blocks.But the code doesnot work.Can anyone help me in sorting out this issue.
My requirement:
Source XSD Structure:
This Source structure is under namespcae: urn:kk:xi:pp:rm:pf:lllll:log:100
<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"><xsd:element name="ABCDEF"><xsd:complexType><xsd:sequence><xsd:element name="IDOC" type="XXXX"/></xsd:sequence></xsd:complexType></xsd:element> and so on
Target:
Now i have to implement the XSlt mapping to change the namepspace of the above structure to urn:sap-com:document:sap:idoc:messages
and the rootnode (i.e ABCDEF in the above example) to COND04.
Over view:
namespace:
urn:kk:xi:pp:rm:pf:lllll:log:100 to urn:sap-com:document:sap:idoc:messages
rootnode
ABCDEF to COND04
Hi,
I think you don't even need to use XSLT mapping, same can be achieved with graphical mapping if you use the approach described by Sunil Chandra in his blog here:
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
But Client asks us to implement only XSLT mapping.can you please give me some inputs how can we achieve.the Source structure is an IDOC XML with different rootname and we haev to change that rootname to the IDOC name using XSLT.I tried some code like below:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Sourcerootname">
<targetrootnodename>
<xsl:apply-templates select="."/>
</targetrootnodename>
</xsl:template>
</xsl:stylesheet>
Please let me know how to proceed with XSLT.
Hi Santhoshi,
of course Martin and Greg are right, Message Mapping would be much easier.
If you have to use pure xsl, then there is no other way than to map each field value with xsl:value-of and produce each repeatable field with xsl:for-each.
So the easiest way is to take a complete target instance copy it into a basic stylesheet and replace the text nodes with xsl:value-of. The elements with occurence 0-unbound are reduced to 1 and you build a xsl:for-each around.
-> some manually work to do..
/Udo
In this case, instead of xsl:copy use xsl:element to dynamically create the elements with XPath function local-name(). Like this, the namespace won't be copied to the result tree.
Found here
<xsl:template match="*|@*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Hi Guys,
I tried the above code but doesnot work.Still i stuck with the code.
My input is nothing but IDOC XML.
Source Input:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="ABCD">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="IDOC" type="COND04" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="COND04">
<xsd:annotation>
<xsd:documentation>
Extension IDOC referring to basic IDOC type COND04 </xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="EDI_DC40" type="EDI_DC40.COND04" />
<xsd:element name="COND04" type="COND04" maxOccurs="9999" />
</xsd:sequence> and ......................................
Output should be:
same as above but instead of ABCD i need to Populate COND04.
I have to use XSLT.Please suggest the correct way how to proceed ??
Thanks in advance.
You need to combine with your template from above, something like this will replace the ABCD node with COND04, you may need to add IDoc namespaces
<xsl:template match="*|@*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="ABCD">
<COND04>
<xsl:apply-templates/>
</COND04>
</xsl:template>
Hi Santhoshi,
I think you can create an XSLT with Martin pointers.
Try the below XSLT program for your requirement as well. This program will just look for element name 'ABCDEF' and replace it with COND04. Also the namespace is added forcefully to get it replaced with the existing one.
XSLT:
=================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="yes" indent="yes"/>
<!-- Template to copy all the elements -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Overrite the element with attribute name 'ABCDEF' with required name 'COND04' -->
<xsl:template match="@*[.='ABCDEF']">
<xsl:attribute name="{name()}">COND04</xsl:attribute>
</xsl:template>
<!-- Adding required namespace which will replace the existing one -->
<xsl:template match="*">
<xsl:element name="xsd:{local-name()}" namespace="urn:sap-com:document:sap:idoc:messages">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
==============================================================
Hope this will help you to resolve and let us know if there are any issues.
Thanks!
Praveen.
Hi Praveen,
Thanks for your reply.When i am trying to execute the above code it is giving the following error:
Error at XSL: output on line 5 col 71 of examp.xsl(i saved it with examp name) XTSE570: method must be xml,html,xhtml or text prefixed name.
Could you please helpme out.
Thanks in advance
I recommend using message mapping instead of XSLT, since if you intended to use the xsl:copy or xsl:copy-of elements, the namespaces of the source will be copied to the target, refer to http://www.w3schools.com/xsl//el_copy-of.asp.
You can easily map the substructure with toolbar function in the mapping
"Map Selected Fields and Substructures if Names Are Identical".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.