title: XSLT copy/copy-of without keeping namespaces
body: <p>Hi I have issue in the default namespace declaration. output xml elements are appended with the default namespace. </p>
  
  <p>The input XML look like</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;m:Request xmlns:m="http://www.NeededNamespace/1.4.0"&gt;
           &lt;Details&gt;
              &lt;Records&gt;50&lt;/Records&gt;
              &lt;Start&gt;1&lt;/Start&gt;
              &lt;sortName&gt;sortName&lt;/sortName&gt;
           &lt;/Details&gt;
           &lt;search&gt;
              &lt;criteria&gt;
                 &lt;comparative&gt;
                    &lt;Comparative&gt;exactMatch&lt;/Comparative&gt;
                 &lt;/comparative&gt;
                 &lt;name&gt;STATECODE&lt;/name&gt;
                 &lt;value&gt;CO&lt;/value&gt;
              &lt;/criteria&gt;
              &lt;criteria&gt;
                 &lt;comparative&gt;
                    &lt;Comparative&gt;exactMatch&lt;/Comparative&gt;
                 &lt;/comparative&gt;
                 &lt;name&gt;Version&lt;/name&gt;
                 &lt;value&gt;4.0&lt;/value&gt;
              &lt;/criteria&gt;
              &lt;criteria&gt;
                 &lt;comparative&gt;
                    &lt;Comparative&gt;contains&lt;/Comparative&gt;
                 &lt;/comparative&gt;
                 &lt;name&gt;LEGALNAME&lt;/name&gt;
                 &lt;value&gt;Citizens State Bank&lt;/value&gt;
              &lt;/criteria&gt;
           &lt;/search&gt;
        &lt;/m:Request&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The XSLT look like</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;xsl:stylesheet version="1.0" exclude-result-prefixes="t" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.NotRequirednamespace.com"&gt;
     &lt;xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/&gt;
     &lt;xsl:strip-space elements="*"/&gt;
     &lt;!--Stylesheet to remove all namespaces from a document--&gt;
     &lt;!--NOTE: this will lead to attribute name clash, if an element contains
          two attributes with same local name but different namespace prefix--&gt;
     &lt;!--Nodes that cannot have a namespace are copied as such--&gt;
     &lt;xsl:template match="/"&gt;
        &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
           &lt;soap:Header&gt;
              &lt;xys:To xmlns:xys="http://services.xys.com/framework/xysHeader/v2"&gt;
                 &lt;xys:version&gt;9.0&lt;/xys:version&gt;
                 &lt;xys:serviceName&gt;DetailsManagement&lt;/xys:serviceName&gt;
                 &lt;xys:QOS&gt;DEFAULT&lt;/xys:QOS&gt;
                 &lt;xys:operation&gt;GetDetails&lt;/xys:operation&gt;
              &lt;/xys:To&gt;
              &lt;ConsumerInfo xmlns="http://services.xys.com/framework/xysHeader/v2"&gt;
                 &lt;xysApplicationName&gt;SAP&lt;/xysApplicationName&gt;
                 &lt;xysCheckPermission&gt;-1&lt;/xysCheckPermission&gt;
                 &lt;xysConsumerPlatform&gt;CS&lt;/xysConsumerPlatform&gt;
                 &lt;xysLanguage&gt;en&lt;/xysLanguage&gt;
                 &lt;xysLocale&gt;US&lt;/xysLocale&gt;
                 &lt;xysLogLevel&gt;false&lt;/xysLogLevel&gt;
              &lt;/ConsumerInfo&gt;
              &lt;HeaderMetadata xmlns="http://services.xys.com/framework/xysHeader/v2"&gt;
                 &lt;metadataContractVersion&gt;2.0&lt;/metadataContractVersion&gt;
                 &lt;Id&gt;414&lt;/Id&gt;
                 &lt;Timestamp&gt;2014-11-20T14:17:30.908-0500&lt;/Timestamp&gt;
              &lt;/HeaderMetadata&gt;
              &lt;xys:favouriteSausage xmlns:xys="http://services.xys.com/framework/xysHeader/v2"&gt;cumberland&lt;/xys:favouriteSausage&gt;
           &lt;/soap:Header&gt;
           &lt;soap:Body&gt;
              &lt;GetDetails xmlns="http://www.NeededNamespace/1.4.0"&gt;
                 &lt;Message id="" version="" bodyType="FS-XML" timeStampCreated="2015-10-11T10:15:25.9144403-04:00" sourceLogicalId="" xmlns="http://www.ibm.com/industries/xys"&gt;
                    &lt;ACGroup bodyCategory="" TPMode="RespondError"/&gt;
                    &lt;COMMAND&gt;
  
                       &lt;xsl:apply-templates/&gt;
  
                    &lt;/COMMAND&gt;
                 &lt;/Message&gt;
              &lt;/GetDetails&gt;
           &lt;/soap:Body&gt;
        &lt;/soap:Envelope&gt;
     &lt;/xsl:template&gt;
  
     &lt;!--template to copy elements--&gt;
     &lt;xsl:template match="*"&gt;
        &lt;xsl:element name="{local-name()}" namespace="http://www.NeededNamespace/1.4.0"&gt;
           &lt;xsl:apply-templates select="@* | node()"/&gt;
        &lt;/xsl:element&gt;
     &lt;/xsl:template&gt;
  
     &lt;!--template to copy attributes--&gt;
     &lt;xsl:template match="@*"&gt;
        &lt;xsl:attribute name="{local-name()}"&gt;
           &lt;xsl:value-of select="."/&gt;
        &lt;/xsl:attribute&gt;
     &lt;/xsl:template&gt;
  
     &lt;!--template to copy the rest of the nodes--&gt;
     &lt;xsl:template match="comment() | text() | processing-instruction()"&gt;
        &lt;xsl:copy/&gt;
     &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The output XML what i am getting is</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;soap:Header&gt;
  &lt;xys:To xmlns:xys="http://services.xys.com/framework/xysHeader/v2"&gt;
  &lt;xys:version&gt;9.0&lt;/xys:version&gt;
  &lt;xys:serviceName&gt;DetailsManagement&lt;/xys:serviceName&gt;
  &lt;xys:QOS&gt;DEFAULT&lt;/xys:QOS&gt;
  &lt;xys:operation&gt;GetDetails&lt;/xys:operation&gt;
  &lt;/xys:To&gt;
  &lt;ConsumerInfo xmlns="http://services.xys.com/framework/xysHeader/v2"&gt;
  &lt;xysApplicationName&gt;SAP&lt;/xysApplicationName&gt;
  &lt;xysCheckPermission&gt;-1&lt;/xysCheckPermission&gt;
  &lt;xysConsumerPlatform&gt;CS&lt;/xysConsumerPlatform&gt;
  &lt;xysLanguage&gt;en&lt;/xysLanguage&gt;
  &lt;xysLocale&gt;US&lt;/xysLocale&gt;
  &lt;xysLogLevel&gt;false&lt;/xysLogLevel&gt;
  &lt;/ConsumerInfo&gt;
  &lt;HeaderMetadata xmlns="http://services.xys.com/framework/xysHeader/v2"&gt;
  &lt;metadataContractVersion&gt;2.0&lt;/metadataContractVersion&gt;
  &lt;Id&gt;414&lt;/Id&gt;
  &lt;Timestamp&gt;2014-11-20T14:17:30.908-0500&lt;/Timestamp&gt;
  &lt;/HeaderMetadata&gt;
  &lt;xys:favouriteSausage xmlns:xys="http://services.xys.com/framework/xysHeader/v2"&gt;cumberland&lt;/xys:favouriteSausage&gt;
  &lt;/soap:Header&gt;
  &lt;soap:Body&gt;
  &lt;GetDetails xmlns="http://www.NeededNamespace/1.4.0"&gt;
  &lt;Message xmlns="http://www.ibm.com/industries/xys" id="" version="" bodyType="FS-XML" timeStampCreated="2015-10-11T10:15:25.9144403-04:00" sourceLogicalId=""&gt;
  &lt;ACGroup bodyCategory="" TPMode="RespondError"/&gt;
  &lt;COMMAND&gt;
  &lt;Request xmlns="http://www.NeededNamespace/1.4.0"&gt;
  &lt;Details&gt;
  &lt;Records&gt;50&lt;/Records&gt;
  &lt;Start&gt;1&lt;/Start&gt;
  &lt;sortName&gt;sortName&lt;/sortName&gt;
  &lt;/Details&gt;
  &lt;search&gt;
  &lt;criteria&gt;
  &lt;comparative&gt;
  &lt;Comparative&gt;exactMatch&lt;/Comparative&gt;
  &lt;/comparative&gt;
  &lt;name&gt;STATECODE&lt;/name&gt;
  &lt;value&gt;CO&lt;/value&gt;
  &lt;/criteria&gt;
  &lt;criteria&gt;
  &lt;comparative&gt;
  &lt;Comparative&gt;exactMatch&lt;/Comparative&gt;
  &lt;/comparative&gt;
  &lt;name&gt;Version&lt;/name&gt;
  &lt;value&gt;4.0&lt;/value&gt;
  &lt;/criteria&gt;
  &lt;criteria&gt;
  &lt;comparative&gt;
  &lt;Comparative&gt;contains&lt;/Comparative&gt;
  &lt;/comparative&gt;
  &lt;name&gt;LEGALNAME&lt;/name&gt;
  &lt;value&gt;Citizens State Bank&lt;/value&gt;
  &lt;/criteria&gt;
  &lt;/search&gt;
  &lt;/Request&gt;
  &lt;/COMMAND&gt;
  &lt;/Message&gt;
  &lt;/GetDetails&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>But in the result I am getting the element as</p>
  
  <pre><code>&lt;Request xmlns="http://www.NeededNamespace/1.4.0"&gt;
  </code></pre>
  
  <p>But i want the result tag as like below</p>
  
  <pre><code>&lt;Request&gt;
  </code></pre>
  
  <p>I dont want to redeclare the namespace which is already declared in the root tag of the same. I have tried all the option i have known and tried for last few days. can you please help me on this.</p>