2

I have a following XML

<?xml version="1.0"?>
<location>
<Destination>Des01</Destination>
<DesCode>ACD8701</DesCode>
<UniqueId>023154</UniqueId>
<Amount>26</Amount>
</location>

I want to change the <location> into <abc_ItemUpdate> and add namespace so the output should look like the following after using XSLT

<ns0:abc_ItemUpdate xmlns:ns0="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo">
    <ns0:Destination>Des01</ns0:LegalEntity>
    <ns0:DesCode>ACD8701</ns0:DesCode>
    <ns0:UniqueId>023154</ns0:UniqueId>
    <ns0:Amount>26</ns0:Amount>
</ns0:abc_ItemUpdate>

Thanks in advance

1 Answer 1

2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output indent="yes"/>

 <xsl:template match="/location">

     <xsl:element name="ns0:abc_ItemUpdate" namespace="http://yournms">
         <!-- copy attributes if any -->
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates/>
     </xsl:element>

 </xsl:template>

 <xsl:template match="*">
     <xsl:element name="ns0:{name()}" namespace="http://yournms">
         <!-- copy attributes if any -->
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates/>
     </xsl:element>
 </xsl:template>

</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

1 Comment

I would make one minor change: use name="ns0:{local-name()}" so it still works if applied to input that already uses namespace prefixes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.