views:

104

answers:

2

I have some XML similar to this:

<envelope xmlns="http://test"&gt;
  <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  A: 
<xsl:template match="element1">
    <xsl:element name="element1" namespace="http:..."/>
</xsl:template>
Maurice Perry
+1  A: 

Use Attribute Value Templates with name()

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

with identity transformation will give you

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