title: Cannot add namespace prefix to children using XSL
body: <p>I checked many answers here and I think I am almost there. One thing that is bugging me (and for some reason my peer needs it) follows:</p>
  
  <h2>I have the following input XML:</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;MyRoot&gt;
    &lt;MyRequest CompletionCode="0" CustomerID="9999999999"/&gt;
    &lt;List TotalList="1"&gt;
      &lt;Order CustomerID="999999999" OrderNo="0000000001" Status="Shipped"&gt;
        &lt;BillToAddress ZipCode="22221"/&gt;
        &lt;ShipToAddress ZipCode="22222"/&gt;
        &lt;Totals Tax="0.50" SubTotal="10.00" Shipping="4.95"/&gt;
      &lt;/Order&gt;
    &lt;/List&gt;
    &lt;Errors/&gt;
  &lt;/MyRoot&gt;
  </code></pre>
  
  <h2>I was asked to produce this:</h2>
  
  <pre><code>&lt;ns:MyNewRoot xmlns:ns="http://schemas.foo.com/response"  
  xmlns:N1="http://schemas.foo.com/request"  
  xmlns:N2="http://schemas.foo.com/details"&gt;
      &lt;N1:MyRequest CompletionCode="0" CustomerID="9999999999"/&gt;
      &lt;ns:List TotalList="1"&gt;
              &lt;N2:Order CustomerID="999999999" Level="Preferred" Status="Shipped"&gt;
                      &lt;N2:BillToAddress ZipCode="22221"/&gt;
                      &lt;N2:ShipToAddress ZipCode="22222"/&gt;
                      &lt;N2:Totals Tax="0.50" SubTotal="10.00" Shipping="4.95"/&gt;
              &lt;/N2:Order&gt;
      &lt;/ns:List&gt;
      &lt;ns:Errors/&gt;
  &lt;/ns:MyNewRoot&gt;
  </code></pre>
  
  <p>Note the children of the N2:Order also needs N2: prefix as well as the ns: prefix for the rest of the elements. </p>
  
  <h2>I use the XSL transformation below:</h2>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
   &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&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;xsl:template match="/MyRoot"&gt;
   &lt;MyNewRoot xmlns="http://schemas.foo.com/response"
     xmlns:N1="http://schemas.foo.com/request"
     xmlns:N2="http://schemas.foo.com/details"&gt;
       &lt;xsl:apply-templates/&gt;
   &lt;/MyNewRoot&gt;
   &lt;/xsl:template&gt;
  
  &lt;xsl:template match="/MyRoot/MyRequest"&gt;
    &lt;xsl:element name="N1:{name()}" namespace="http://schemas.foo.com/request"&gt;
      &lt;xsl:copy-of select="namespace::*"/&gt;
      &lt;xsl:apply-templates select="@* | node()"/&gt;
    &lt;/xsl:element&gt;
   &lt;/xsl:template&gt;
  
   &lt;xsl:template match="/MyRoot/List/Order"&gt;
    &lt;xsl:element name="N2:{name()}" namespace="http://schemas.foo.com/details"&gt;
      &lt;xsl:copy-of select="namespace::*"/&gt;
      &lt;xsl:apply-templates select="@* | node()"/&gt;
    &lt;/xsl:element&gt;
   &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This one doesn't process the ns (I couldn't figure this out). When I process thru the above the XSL transformation with AltovaXML I end up with below:</p>
  
  <pre><code>&lt;MyNewRoot xmlns="http://schemas.foo.com/response"  
  xmlns:N1="http://schemas.foo.com/request"  
  xmlns:N2="http://schemas.foo.com/details"&gt;
      &lt;N1:MyRequest CompletionCode="0" CustomerID="9999999999"/&gt;
      &lt;List xmlns="" TotalList="1"&gt;
              &lt;N2:Order CustomerID="999999999" Level="Preferred" Status="Shipped"&gt;
                      &lt;BillToAddress ZipCode="22221"/&gt;
                      &lt;ShipToAddress ZipCode="22222"/&gt;
                      &lt;Totals Tax="0.50" SubTotal="10.00" Shipping="4.95"/&gt;
              &lt;/N2:Order&gt;
      &lt;/List&gt;
      &lt;Errors/&gt;
  &lt;/MyNewRoot&gt;
  </code></pre>
  
  <p>Note that N2: prefix for the children of Order is not there after the XSL transformation. Also additional xmlns="" in the Order header (for some reason). I couldn't figure out putting the ns: prefix for the rest of the elements (like Errors and List). </p>
  
  <p>First of all, why would I need to put the prefix for the children if the parent already has it. Doesn't the parent namespace dictate the children nodes/attribute namespaces?  </p>
  
  <h2>Secondly, I want to add the prefixes in the above XML as expected, how can I do that with XSL?</h2>