title: How to add namespace and prefix for all elements and attributes using XSLT?
body: <p>My problem is how to add namespace and prefix for all elements and attributes using XSLT?
  My input xml as is....</p>
  
  <pre><code>&lt;ProcessCreditMemo xmlns='CreditMemo' 
                     xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
                     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                     xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;
  &lt;ORDER_HEADERDetails&gt;
      &lt;ORDER_HEADER&gt;
      &lt;NAME&gt;0010185214&lt;/NAME&gt;
  </code></pre>
  
  <p>to be...</p>
  
  <pre><code>&lt;ns0:ProcessCreditMemo xmlns='CreditMemo' 
                         xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
                         xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                         xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' 
                         xmlns:ns0="http://tempuri.org/"&gt;
  &lt;ns0:ORDER_HEADERDetails&gt;
      &lt;ns0:ORDER_HEADER&gt;
     &lt;ns0:NAME&gt;0010185214&lt;/NAME&gt;
  </code></pre>
  
  <p>I need add the prefix "ns0:" for all elements and attributes, and add the namespace "xmlns:ns0="http://tempuri.org/" in the header "ProcessCreditMemo".</p>
  
  <p>I am trying to build a XSLT to do it...</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;xsl:output method="xml" encoding="UTF-8" indent="yes"/&gt;
  &lt;xsl:template match="node()|text()|@*"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:if test="local-name()='ProcessCreditMemo'"&gt;
              &lt;xsl:attribute name="xmlns" namespace="http://tempuri.org/" /&gt;
          &lt;/xsl:if&gt;
  </code></pre>
  
  <p>but the resulting XML duplicates the prefix with empty value.</p>
  
  <pre><code>&lt;ProcessCreditMemo xmlns="CreditMemo" 
                     xmlns:ns0="http://tempuri.org/" 
                     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                     ns0:xmlns=""&gt;
  </code></pre>