title: xstl transform inserts namespace in result elements (revisited)
body: <p>I have an xml file where I need to rename elements.   (also later to transform elements to attributes).   The xslt transform inserts the default namespace into all the top level elements.   I don't want that.   I have seen quite a number of questions about this problem but still having issues with the desired result and understanding why...</p>
  <ol>
  <li>The best I can do with exclude-result-prefixes is:</li>
  </ol>
  <pre><code>&lt;ar xmlns=&quot;&quot;&gt;
  &lt;dyu xmlns=&quot;http://www.coastsystems.net&quot;&gt;ábada&lt;/dyu&gt;
  </code></pre>
  <p>Why is the namespace removed from only ar?  And why does it preserve the xmlns=&quot;&quot;?</p>
  <ol start="2">
  <li>If i <strong>remove</strong> the renaming portion of the transform so it basically just copies the original file:</li>
  </ol>
  <pre><code>      &lt;xsl:template match=&quot;/c:lexique/c:headword&quot;&gt;                                                                                                     
        &lt;ar&gt;                                                                                                                                           
          &lt;xsl:apply-templates select=&quot;@* | node()&quot;/&gt;                                                                                                  
        &lt;/ar&gt;                                                                                                                                          
        &lt;/xsl:template&gt;  
  </code></pre>
  <p>then 'exclude-result-prefixes' seems to have no effect at all.  Whether its there or not there is no namespace inserted.  Why?</p>
  <p>Is there a hitch with xslt3?   I need to use this as it handles the latin extended characters and sorting correctly.</p>
  <p>The xml is as follows:</p>
  <pre><code>    &lt;?xml version='1.0' encoding='utf-8'?&gt;                                                                                                             
  &lt;lexique xmlns=&quot;http://www.coastsystems.net&quot;                                                                                                       
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;                                                                                     
           xsi:schemaLocation=&quot;http://www.coastsystems.net headwords2.xsd&quot;                                                                           
  &gt;                                                                                                                                                  
    &lt;headword&gt;                                                                                                                                       
      &lt;dyu&gt;ábada&lt;/dyu&gt;                                                                                                                               
      &lt;alt&gt;abada&lt;/alt&gt;                                                                                                                               
      &lt;emp&gt;&lt;/emp&gt;                                                                                                                                    
      &lt;cf&gt;fewu&lt;/cf&gt;                                                                                                                                  
      &lt;trans&gt;                                                                                                                                        
        &lt;lang&gt;fr&lt;/lang&gt;                                                                                                                              
        &lt;detail&gt;&lt;/detail&gt;                                                                                                                            
        &lt;speech&gt;                                                                                                                                     
          &lt;type&gt;&lt;/type&gt;                                                                                                                              
          &lt;t-uuid&gt;7b8612bc-23c7-4241-817f-f6fcd9bff8ac&lt;/t-uuid&gt;                                                                                      
          &lt;def&gt;                                                                                                                                      
            &lt;gloss&gt;jamais&lt;/gloss&gt;                                                                                                                    
            &lt;gl-id&gt;bbc05aae-8f08-4ab7-91ae-3b52533a896f&lt;/gl-id&gt;                                                                                      
            &lt;note2&gt;&lt;/note2&gt;                                                                                                                          
            &lt;note3&gt;&lt;/note3&gt;                                                                                                                          
            &lt;note4&gt;&lt;/note4&gt;                                                                                                                          
            &lt;tags&gt;&lt;/tags&gt;                                                                                                                            
            &lt;example&gt;                                                                                                                                
              &lt;source&gt;a tɛ koɲuman kɛ abada.&lt;/source&gt;                                                                                                
              &lt;target&gt;Il ne fait jamais quelque chose de bien.&lt;/target&gt;                                                                              
              &lt;ex-id&gt;2c592b68-0d29-4b6c-8614-005adab4fba5&lt;/ex-id&gt;                                                                                    
            &lt;/example&gt;                                                                                                                               
          &lt;/def&gt;                                                                                                                                     
        &lt;/speech&gt;                                                                                                                                    
      &lt;/trans&gt;                                                                                                                                       
    &lt;/headword&gt;                                                                                                                                      
  &lt;/lexique&gt;               
  </code></pre>
  <p>With the xslt stylesheet:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;                                                                                                                              
  &lt;xsl:stylesheet version=&quot;2.0&quot;                                                                                                                      
    xmlns:xsl  = &quot;http://www.w3.org/1999/XSL/Transform&quot;                                                                                              
    xmlns:c=&quot;http://www.coastsystems.net&quot;                                                                                                            
    exclude-result-prefixes=&quot;xsl c&quot;                                                                                                                  
  &gt;                                                                                                                                                  
   &lt;xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;UTF-8&quot; /&gt;                                                                                         
                                                                                                                                                     
                                                                                                                                                     
   &lt;xsl:template match=&quot;/&quot;&gt;                                                                                                                          
      &lt;xsl:apply-templates select=&quot;@*|node()&quot;/&gt;                                                                                                      
    &lt;/xsl:template&gt;                                                                                                                                  
                                                                                                                                                     
    &lt;xsl:template match=&quot;@*|node()&quot;&gt;                                                                                                                 
      &lt;xsl:copy&gt;                                                                                                                                     
        &lt;xsl:apply-templates select=&quot;@*|node()&quot;/&gt;                                                                                                    
      &lt;/xsl:copy&gt;                                                                                                                                    
    &lt;/xsl:template&gt;                                                                                                                                  
                                                                                                                                                     
    &lt;xsl:template match=&quot;/c:lexique/c:headword&quot;&gt;                                                                                                     
      &lt;ar&gt;                                                                                                                                           
        &lt;xsl:apply-templates select=&quot;@* | node()&quot;/&gt;                                                                                                  
      &lt;/ar&gt;                                                                                                                                          
    &lt;/xsl:template&gt;                                                                                                                                  
                                                                                                                                                     
  &lt;/xsl:stylesheet&gt;           
  </code></pre>
  <p>(<code>xslt3 -xsl:rename.xsl -s:headwords.xml)</code> Outputs:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;lexique xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.coastsystems.net&quot; xsi:schemaLocation=&quot;http://www.coastsystems.net headwords2.xsd&quot;&gt;
     &lt;ar xmlns=&quot;&quot;&gt;
        &lt;dyu xmlns=&quot;http://www.coastsystems.net&quot;&gt;ábada&lt;/dyu&gt;
        &lt;alt xmlns=&quot;http://www.coastsystems.net&quot;&gt;abada&lt;/alt&gt;
        &lt;emp xmlns=&quot;http://www.coastsystems.net&quot;/&gt;
        &lt;cf xmlns=&quot;http://www.coastsystems.net&quot;&gt;fewu&lt;/cf&gt;
        &lt;trans xmlns=&quot;http://www.coastsystems.net&quot;&gt;
           &lt;lang&gt;fr&lt;/lang&gt;
           &lt;detail/&gt;
           &lt;speech&gt;
              &lt;type/&gt;
              &lt;t-uuid&gt;7b8612bc-23c7-4241-817f-f6fcd9bff8ac&lt;/t-uuid&gt;
              &lt;def&gt;
                 &lt;gloss&gt;jamais&lt;/gloss&gt;
                 &lt;gl-id&gt;bbc05aae-8f08-4ab7-91ae-3b52533a896f&lt;/gl-id&gt;
                 &lt;note2/&gt;
                 &lt;note3/&gt;
                 &lt;note4/&gt;
                 &lt;tags/&gt;
                 &lt;example&gt;
                    &lt;source&gt;a tɛ koɲuman kɛ abada.&lt;/source&gt;
                    &lt;target&gt;Il ne fait jamais quelque chose de bien.&lt;/target&gt;
                    &lt;ex-id&gt;2c592b68-0d29-4b6c-8614-005adab4fba5&lt;/ex-id&gt;
                 &lt;/example&gt;
              &lt;/def&gt;
           &lt;/speech&gt;
        &lt;/trans&gt;
     &lt;/ar&gt;
  </code></pre>
  <p>Desired output:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;lexique xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.coastsystems.net&quot; xsi:schemaLocation=&quot;http://www.coastsystems.net headwords2.xsd&quot;&gt;
     &lt;ar&gt;
        &lt;dyu&gt;ábada&lt;/dyu&gt;
        &lt;alt&gt;abada&lt;/alt&gt;
        &lt;emp/&gt;
        &lt;cf&gt;fewu&lt;/cf&gt;
        &lt;trans&gt;
           &lt;lang&gt;fr&lt;/lang&gt;
           &lt;detail/&gt;
  =====  snipped
  </code></pre>