title: XSLT copy node without namespace
body: <p>(XML version="1.0") I'm quite new to XSLT. I have been given the the following XML:</p>
  
  <pre><code>&lt;SNAPSHOTS&gt;
    &lt;SNAPSHOT&gt;
      &lt;ID&gt;1&lt;/ID&gt;
      &lt;STATUS&gt;COM&lt;/STATUS&gt;
    &lt;/SNAPSHOT&gt;
    &lt;SNAPSHOT&gt;
      &lt;ID&gt;2&lt;/ID&gt;
      &lt;STATUS&gt;ACC&lt;/STATUS&gt;
    &lt;/SNAPSHOT&gt;
  &lt;/SNAPSHOTS&gt;
  </code></pre>
  
  <p>As of my requirements I've managed to transformed the provided XML to be contained within a <code>&lt;DC&gt;</code> root element and include a header before the <code>&lt;SNAPSHOTS&gt;</code> element.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;DC&gt;
    &lt;Header&gt;
      &lt;FileName&gt;TEST.xml&lt;/FileName&gt;
      &lt;NoOfRecords&gt;2&lt;/NoOfRecords&gt;
    &lt;/Header&gt;
  
    &lt;SNAPSHOTS&gt;
      &lt;SNAPSHOT&gt;
        &lt;ID&gt;1&lt;/ID&gt;
        &lt;STATUS&gt;COM&lt;/STATUS&gt;
      &lt;/SNAPSHOT&gt;
      &lt;SNAPSHOT&gt;
        &lt;ID&gt;2&lt;/ID&gt;
        &lt;STATUS&gt;ACC&lt;/STATUS&gt;
      &lt;/SNAPSHOT&gt;
    &lt;/SNAPSHOTS&gt;
  &lt;DC&gt;
  </code></pre>
  
  <p>This is the XSD I've created:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
      &lt;xsl:output method="xml" indent="yes" /&gt;
  
      &lt;xsl:template match="/"&gt;
          &lt;DC&gt;
           &lt;Header&gt;
              &lt;FileName&gt;TEST.xml&lt;/FileName&gt;
              &lt;NoOfRecords&gt;&lt;xsl:value-of select="count(SNAPSHOTS/SNAPSHOT)"/&gt;&lt;/NoOfRecords&gt;
           &lt;/Header&gt;
          &lt;xsl:apply-templates select="node()"/&gt;
          &lt;/DC&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:strip-space elements="*"/&gt;
  
       &lt;xsl:template match="node()" name="removeNode"&gt;
           &lt;xsl:copy&gt;
             &lt;xsl:apply-templates select="node()"/&gt;
           &lt;/xsl:copy&gt;
       &lt;/xsl:template&gt;
  
   &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>When I include <strong>namespaces</strong> into the <code>&lt;DC&gt;</code> the namespace gets copied to the  node also.</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
      &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
          &lt;xsl:output method="xml" indent="yes" /&gt;
  
          &lt;xsl:template match="/"&gt;
              &lt;DC xmlns="http://TEST/TEST.xsd"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;&lt;-- NAMESPACE ADDED
               &lt;Header&gt;
                  &lt;FileName&gt;TEST.xml&lt;/FileName&gt;
                  &lt;NoOfRecords&gt;&lt;xsl:value-of select="count(SNAPSHOTS/SNAPSHOT)"/&gt;&lt;/NoOfRecords&gt;
               &lt;/Header&gt;
              &lt;xsl:apply-templates select="node()"/&gt;
              &lt;/DC&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;DC xmlns="http://TEST/TEST.xsd"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Header&gt;
      &lt;FileName&gt;TEST.xml&lt;/FileName&gt;
      &lt;NoOfRecords&gt;2&lt;/NoOfRecords&gt;
    &lt;/Header&gt;
  
    &lt;SNAPSHOTS xmlns=""&gt;    &lt;&lt;--INCORRECT
      &lt;SNAPSHOT&gt;
        &lt;ID&gt;1&lt;/ID&gt;
        &lt;STATUS&gt;COM&lt;/STATUS&gt;
      &lt;/SNAPSHOT&gt;
      &lt;SNAPSHOT&gt;
        &lt;ID&gt;2&lt;/ID&gt;
        &lt;STATUS&gt;ACC&lt;/STATUS&gt;
      &lt;/SNAPSHOT&gt;
    &lt;/SNAPSHOTS&gt;
  &lt;DC&gt;
  </code></pre>
  
  <p>I've tried many solutions (Googling 'XSLT copy node without namespace' etc.). One of the way's I've tried is the following (<a href="https://stackoverflow.com/questions/19998180/xsl-copy-nodes-without-xmlns">xsl copy nodes without xmlns</a>) but It does not remove the xmlns=""</p>
  
  <pre><code>&lt;xsl:apply-templates select="*"  mode="copy-no-namespaces"/&gt;
  
  &lt;xsl:template match="*" mode="copy-no-namespaces"&gt;
      &lt;xsl:element name="{local-name()}"&gt;
          &lt;xsl:copy-of select="@*"/&gt;
          &lt;xsl:apply-templates select="node()" mode="copy-no-namespaces"/&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>I've also read the following but don't fully understand the accepted answer.
  <a href="https://stackoverflow.com/questions/21397126/xslt-to-copy-element-without-namespace">enter link description here</a></p>
  
  <p>I have been working on this for hours and there is obviously something I just don't get. I sorry if I'm missing something simple considering similar questions have been asked before!! Many thanks your any help you can provide! Thomas</p>