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

kalyangkmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
<?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

0
kalyangkmAuthor Commented:
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

0
Geert BormansInformation ArchitectCommented:
yes, it might have some side effects since you start from the document element, I tend to start from the root element, but it should mostly do the same

I prefer making the deep copy explicit through identity copy templates, because that gives me an elegant entry for minor tweaking at every level
But that is a style choice in this task
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.