title: XSL for removing or changing empty xmlns on xml document
body: <p>A synchronous SOAP web service is answering my request with a xml document which has an element with an empty xmlns attribute (<code>&lt;element xmlns=&quot;&quot;&gt;value&lt;/element&gt;</code>). This is, of course, messing with the program in charge of processing this response.</p>
  <p>I would like to apply an XSL transformation to get rid of the empty xmlns or changing it to the proper namespace.
  So far XSL stylesheets I have found here or in other websites don't work or make the children of the fixed element to have now an empty xmlns.
  My input xml document is as follow:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
      &lt;rootElement xmlns=&quot;http://tempuri.org/&quot;&gt;
          &lt;level1&gt;
              &lt;level2 xmlns=&quot;&quot;&gt;
                  &lt;child1 id=&quot;aNumber&quot; desc=&quot;aString&quot;&gt;
                      &lt;name&gt;name1&lt;/name&gt;
                      &lt;code&gt;code1&lt;/code&gt;
                  &lt;/child1&gt;
                  &lt;child2 desc=&quot;aString&quot;&gt;
                      &lt;field1&gt;field1&lt;/field1&gt;
                      &lt;field2&gt;field2&lt;/field2&gt;
                  &lt;/child2&gt;
              &lt;/level2&gt;
          &lt;/level1&gt;
      &lt;/rootElement&gt;
  </code></pre>
  <p>The best output I got so far with some xsl stylesheets found here got me something like this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;rootElement xmlns=&quot;http://tempuri.org/&quot;&gt;
          &lt;level1&gt;
              &lt;level2&gt;
                    &lt;child1 xmlns=&quot;&quot; desc=&quot;aString&quot; id=&quot;aNumber&quot;&gt;
                          &lt;name&gt;name1&lt;/name&gt;
                          &lt;code&gt;code1&lt;/code&gt;
                    &lt;/child1&gt;
                    &lt;child2 xmlns=&quot;&quot; desc=&quot;aString&quot;&gt;
                          &lt;field1&gt;field1&lt;/field1&gt;
                          &lt;field2&gt;field2&lt;/field2&gt;
                    &lt;/child2&gt;
              &lt;/level2&gt;
          &lt;/level1&gt;
      &lt;/rootElement&gt;
  </code></pre>
  <p>level2 is fixed but now child1 and child 2 have each an empty xmlns. This is making my program to fail too.
  The best and simplest stylesheet that got me so far is this one:</p>
  <pre class="lang-xsl prettyprint-override"><code>&lt;xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns=&quot;http://tempuri.org/&quot;&gt;
      &lt;xsl:output encoding='UTF-8' indent='yes' method='xml'/&gt;
      &lt;!-- copy everything into the output --&gt;
      &lt;xsl:template match='@*|node()'&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select='@*|node()'/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
      &lt;!-- change the namespace declaration for level2 --&gt;
      &lt;xsl:template match=&quot;level2&quot;&gt;
          &lt;level2 xmlns='http://tempuri.org/'&gt;
              &lt;xsl:copy-of select=&quot;@*|node()&quot;/&gt;
          &lt;/level2&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>