title: How can I dynamically set the default namespace declaration of an XSLT transformation's output XML?
body: <p>I can do it, but not for the default namespace, using the <code>&lt;xsl:namespace&gt;.</code> If I try to do it for the default namespace:</p>
  
  <pre><code>&lt;xsl:namespace name="" select"myUri"/&gt;
  </code></pre>
  
  <p>it never works. It demands that I explicitly define the namespace of the element to be able to use the above null prefix declaration.<br>
  The reason I want this is because I have a task to transform an input XML file to another output xml. The output XML has many elements and i dont want to have to explicitly set the namespace for every element. Thats why I want to set the default and never bother again. But the default must be computed from some data in the source XML. It does not change during the whole transformation, but it is dependent on input XML data.
  Any solution? </p>
  
  <p>EDIT 1:
  To sup up:</p>
  
  <ol>
  <li>I want to create a namespace dynamically and set it to be the default namespace of the output xml document. The uri of the namespace is derived from some data in the input XML.</li>
  <li>If I use <code>&lt;xsl:namespace&gt;</code> in my root output element, I cannot create a default namespace for it, only a prefixed one. And even with the prefixed one, it does not propagate to children.</li>
  </ol>
  
  <p>EDIT 2:
   dkackman proposed: </p>
  
  <pre><code>&lt;xsl:template match="root"&gt;
    &lt;xsl:param name ="ns"&gt;my-computed-namespace&lt;/xsl:param&gt;
    &lt;xsl:element name="newRoot" namespace="{$ns}"/&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>It almost solves the problem. Unfortunately the children are injected with ""(blank) namespace by the transformer. Here is what I get if I put a child element:</p>
  
  <pre><code>&lt;newRoot xmlns="my-computed-namespace"&gt; 
      &lt;child xmlns=""&gt; ... 
      &lt;/child&gt; 
   &lt;/newRoot&gt;
  </code></pre>
  
  <p>Why does the transformer put this <code>xmlns=""</code> in the children? If I can prevent this then I have found my solution.</p>