title: Add Namespaces to Root Element
body: <p>I'm writing an XSLT transform where I'd like all namespace prefixes to be defined on the root element.  By default MS seems to create a new prefix definition on the first element in the XML hierarchy to use that schema; meaning the same schema may be referenced on multiple elements should those elements not be related to a shared ancestor of the same schema.</p>
  
  <p>By coding the root element as such, all works as desired:</p>
  
  <pre class="lang-xsl prettyprint-override"><code>&lt;!-- ... --&gt;
  
  &lt;ns0:root xmlns:ns0="http://some/schema" xmlns:ns1 = "http://another/schema"&gt;
      &lt;!-- rest of XSLT; including calls to other templates --&gt;
  &lt;/ns0:root&gt;
  
  &lt;!-- ... --&gt;
  </code></pre>
  
  <p>However I can't find any way to code this using <code>xsl:element</code>; e.g.</p>
  
  <pre class="lang-xsl prettyprint-override"><code>&lt;xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ns0="http://some/schema" 
      xmlns:ns1 = "http://another/schema"
  &gt;
      &lt;!-- ... --&gt;
  
      &lt;xsl:element name="ns0:root"&gt;
          &lt;xsl:attribute name="ns1" namespace="http://www.w3.org/2000/xslns/"&gt;http://another/schema&lt;/xsl:attribute&gt;
          &lt;!-- rest of XSLT; including calls to other templates --&gt;
      &lt;/xsl:element&gt; 
  
      &lt;!-- ... --&gt;
  </code></pre>
  
  <p>Is it possible to declare namespace prefixes against an <code>xls:element</code> for schemas other than that element itself?</p>
  
  <hr>
  
  <h1>Full Example</h1>
  
  <p><strong>XML</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Demo xmlns="http://some/schema"&gt;
      &lt;a&gt;Hello&lt;/a&gt;
      &lt;b&gt;World&lt;/b&gt;
  &lt;/Demo&gt;
  </code></pre>
  
  <p><strong>XSLT</strong></p>
  
  <pre class="lang-xsl prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ns0="http://some/schema" 
      xmlns:ns1 = "http://another/schema"
      exclude-result-prefixes="xsl"
  &gt;
  
      &lt;xsl:output method="xml" indent="yes" version="1.0"/&gt;
      &lt;xsl:strip-space elements="*"/&gt;
  
      &lt;xsl:template match="/*"&gt; 
          &lt;xsl:element name="{name(.)}" namespace="{namespace-uri(.)}"&gt;
              &lt;xsl:apply-templates select="@* | node()" /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  
      &lt;xsl:template match="/ns0:Demo/ns0:a"&gt;
          &lt;xsl:element name="ns1:z"&gt;
              &lt;xsl:value-of select="./text()" /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  
      &lt;xsl:template match="/ns0:Demo/ns0:b"&gt;
          &lt;xsl:element name="ns1:y"&gt;
              &lt;xsl:value-of select="./text()" /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Demo xmlns="http://some/schema"&gt;
      &lt;ns1:z xmlns:ns1="http://another/schema"&gt;Hello&lt;/ns1:z&gt;
      &lt;ns1:y xmlns:ns1="http://another/schema"&gt;World&lt;/ns1:y&gt;
  &lt;/Demo&gt;
  </code></pre>
  
  <p><strong>Desired Result</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Demo xmlns="http://some/schema" xmlns:ns1="http://another/schema"&gt;
      &lt;ns1:z&gt;Hello&lt;/ns1:z&gt;
      &lt;ns1:y&gt;World&lt;/ns1:y&gt;
  &lt;/Demo&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ns0:Demo xmlns:ns0="http://some/schema" xmlns:ns1="http://another/schema"&gt;
      &lt;ns1:z&gt;Hello&lt;/ns1:z&gt;
      &lt;ns1:y&gt;World&lt;/ns1:y&gt;
  &lt;/ns0:Demo&gt;
  </code></pre>