title: XSLT identity transform produces wrong namespace
body: <p>I have a custom XML schema that is evolving: elements are added, others deleted, and the namespace changes to reflect the new version (e.g., from "http://foo/1.0" to "http://foo/1.1"). I want to write an XSLT that converts XML documents from the old schema to the new one. My first attempt works, but it's verbose and unscalable, and I need help refining it.</p>
  
  <p>Here's a sample document for the 1.0 schema:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;foo:rootElement xmlns:foo="http://foo/1.0"&gt;
      &lt;obsolete&gt;something&lt;/obsolete&gt;
      &lt;stuff&gt;
          &lt;alpha&gt;a&lt;/alpha&gt;
          &lt;beta&gt;b&lt;/beta&gt;
      &lt;/stuff&gt;
  &lt;/foo:rootElement&gt;
  </code></pre>
  
  <p>In the 1.1 schema, the "obsolete" element goes away but everything else remains. So the XSLT needs to do two things:</p>
  
  <ol>
  <li>Remove the  tag</li>
  <li>Change the namespace from <a href="http://foo/1.0" rel="nofollow">http://foo/1.0</a> to <a href="http://foo/1.1" rel="nofollow">http://foo/1.1</a></li>
  </ol>
  
  <p>Here's my solution:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:foo1="http://foo/1.0"
      xmlns:foo="http://foo/1.1" 
      exclude-result-prefixes="foo1"&gt;
  
      &lt;xsl:output method="xml" standalone="yes" indent="yes"/&gt;
  
      &lt;!-- Remove the "obsolete" tag --&gt;    
      &lt;xsl:template match="foo1:rootElement/obsolete"/&gt;
  
      &lt;!-- Copy the "alpha" tag --&gt;
      &lt;xsl:template match="foo1:rootElement/stuff/alpha"&gt;
          &lt;alpha&gt;
              &lt;xsl:apply-templates/&gt;
          &lt;/alpha&gt;
      &lt;/xsl:template&gt;
  
      &lt;!-- Copy the "beta" tag --&gt;
      &lt;xsl:template match="foo1:rootElement/stuff/beta"&gt;
          &lt;beta&gt;
              &lt;xsl:apply-templates/&gt;
          &lt;/beta&gt;
      &lt;/xsl:template&gt;
  
      &lt;!-- Copy the "stuff" tag --&gt;
      &lt;xsl:template match="foo1:rootElement/stuff"&gt;
          &lt;stuff&gt;
              &lt;xsl:apply-templates/&gt;
          &lt;/stuff&gt;
      &lt;/xsl:template&gt;
  
      &lt;!-- Copy the "rootElement" tag --&gt;
      &lt;xsl:template match="foo1:rootElement"&gt;
          &lt;foo:rootElement&gt;
              &lt;xsl:apply-templates/&gt;
          &lt;/foo:rootElement&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Although this produces the output I want, notice that I have a copying template for every element in the schema: alpha, beta, etc. For complex schemas with hundreds of kinds of elements, I'd have to add hundreds of templates!</p>
  
  <p>I thought I could eliminate this problem by reducing all those copying templates into a single identity transform, like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:foo1="http://foo/1.0"
      xmlns:foo="http://foo/1.1" 
      exclude-result-prefixes="foo1"&gt;
  
      &lt;xsl:output method="xml" standalone="yes" indent="yes"/&gt;
  
      &lt;xsl:template match="foo1:rootElement/obsolete"/&gt;
  
      &lt;xsl:template match="node()|@*" name="identity"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="node()|@*"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="foo1:rootElement/stuff"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:call-template name="identity"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="foo1:rootElement"&gt;
          &lt;foo:rootElement&gt;
              &lt;xsl:apply-templates/&gt;
          &lt;/foo:rootElement&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>But it produces:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;foo:rootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:foo="http://foo/1.1"&gt;  
      &lt;stuff xmlns:foo="http://foo/1.0"&gt;
        &lt;stuff&gt;
          &lt;alpha&gt;a&lt;/alpha&gt;
          &lt;beta&gt;b&lt;/beta&gt;
        &lt;/stuff&gt;
     &lt;/stuff&gt;
  &lt;/foo:rootElement&gt;
  </code></pre>
  
  <p>The "stuff" element was copied, which is what I want, but it's wrapped in another "stuff" element, tagged with the old namespace. I don't understand why this is happening. I've tried many ways of fixing this but have been unsuccessful. Any suggestions? Thanks.</p>