title: change the namespace of an element with xslt
body: <p>I'd like to make this</p>
  
  <pre><code>&lt;hello&gt;
    &lt;one&gt;
      &lt;paragraph&gt;p1&lt;/paragraph&gt;
    &lt;/one&gt;
  &lt;/hello&gt; 
  </code></pre>
  
  <p>into this</p>
  
  <pre><code>&lt;x:hello y:an_attribute="a value for an_attribute" xmlns:x="some_new_namespace" xmlns:y="other_ns"&gt;
    &lt;one&gt;
      &lt;paragraph&gt;p1&lt;/paragraph&gt;
    &lt;/one&gt;
  &lt;/x:hello&gt; 
  </code></pre>
  
  <p>this is the stylesheet I came up with:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="xml" indent="yes"/&gt;
  
      &lt;xsl:param name="element_localname" select="'hello'"/&gt;
  
  
      &lt;xsl:template match="node()"&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="local-name() = $element_localname"&gt;
                  &lt;xsl:element name="{$element_localname}" namespace="some_new_namespace"&gt;
                      &lt;xsl:attribute name="an_attribute" namespace="other_ns"&gt;a value for an_attribute&lt;/xsl:attribute&gt;
                      &lt;xsl:apply-templates select="node()"/&gt;
                  &lt;/xsl:element&gt;
              &lt;/xsl:when&gt;
  
              &lt;!-- copy the rest as is --&gt;
              &lt;xsl:otherwise&gt; 
                  &lt;xsl:copy&gt;
                      &lt;xsl:apply-templates select="node()" /&gt;
                  &lt;/xsl:copy&gt;
              &lt;/xsl:otherwise&gt;
  
          &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt; 
  </code></pre>
  
  <p>but for some strange reason, the attribute I am adding to the element has the same namespace as the root element itself? why?</p>
  
  <pre><code>&lt;ns0:hello xmlns:ns0="other_ns" ns0:an_attribute="a value for an_attribute"&gt;
    &lt;one&gt;
      &lt;paragraph&gt;p1&lt;/paragraph&gt;
    &lt;/one&gt;
  &lt;/ns0:hello&gt;
  </code></pre>
  
  <p>Thank you for reading.</p>