Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

Changing the xml header and end tags using XSLT

Hi Folks,

I am trying to perform some multi mapping task and for that I would need the XML structure to have additional tags

I have this structure
<?xml version="1.0" encoding="UTF-8"?>
 <ns1:MT_Testing_Out xmlns:ns1="Test.com">
         <TESTING>
            <ABC></ABC>
            <BCD></BCD>
            <LMN></LMN>
         </TESTING>
 </ns1:MT_Testing_Out>

Open in new window


and I need to change it to the following; Can you suggest XSLT to achieve this.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <ns0:Message1>
      <ns1:MT_Testing_Out xmlns:ns1="Test.com">
         <TESTING>
            <ABC></ABC>
            <BCD></BCD>
            <LMN></LMN>
         </TESTING>
      </ns1:MT_Testing_Out>
   </ns0:Message1>
</ns0:Messages>

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns1="Test.com"
    xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge"
     exclude-result-prefixes="ns1"
    version="1.0">
    
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    
    <xsl:template match="ns1:MT_Testing_Out">
        <ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
            <ns0:Message1>
                <ns1:MT_Testing_Out xmlns:ns1="Test.com">
                    <xsl:apply-templates></xsl:apply-templates>
                </ns1:MT_Testing_Out>
            </ns0:Message1>
        </ns0:Messages>
    </xsl:template>
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
     
</xsl:stylesheet>

Open in new window

Avatar of kalyangkm

ASKER

Hi Geert,

Just checking, wont the following code work?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="/">
          <ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
            <ns0:Message1>
                <xsl:copy-of select="."/>
            </ns0:Message1>
        </ns0:Messages>
    </xsl:template>
</xsl:stylesheet>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial