0

I have some XML similar to this:

<envelope xmlns="http://test">
  <header>
    <msgId />
  </header>
  <body>
    <element1 />
  </body>
</envelope>

I want to add a namespace to the <element1> node. Can anyone help me how to do this with XSLT?

1
  • Hi , I have a xml similar to this <envelope xmlns="http:\\test"> <header> <msgId/> </header> <body> <element1> </body> I want to add a namespace to node <element1> . can anyone help me how to do this with xslt <element1 xmlns="http:\\test2"> Thanks Commented Mar 7, 2009 at 21:30

2 Answers 2

1
<xsl:template match="element1">
    <xsl:element name="element1" namespace="http:..."/>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

1

Use Attribute Value Templates with name()

<xsl:template match="element1">
  <xsl:element name="{name()}" namespace="http://other-namespace">
  …

with identity transformation will give you

<envelope xmlns="http:\\test">
  <header>
    <msgId/>
  </header>
  <body>
    <element1 xmlns="http://other-namespace"/>
    …

Comments

Your Answer

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