title: Oracle XMLQuery inserting unwanted namespace
body: <p>Oracle 11.2</p>
  
  <p>Below is a cut down version of an <code>XMLQuery</code> i'm running on an <code>XMLType</code> column. When I run the query, which simply parses and recreates the stored <code>XML</code>, the <strong>unwanted</strong> default and tsip namespaces get inserted into the child elements of the parent. Note that the tsxm namespace does not get inserted, this is because it is not equal to the default namespace This query does nothing and could easily be rewritten, but the real (much bigger) query uses this same methodology so this is why i'm posting the question in this format. </p>
  
  <p>create the table:</p>
  
  <pre><code>CREATE TABLE XML_DOCUMENT_TMP
  (
    DOCUMENT_ID   NUMBER(12)                      NOT NULL,
    XML_DATA      SYS.XMLTYPE                     NOT NULL,
    CREATED_DATE  TIMESTAMP(6)                    NOT NULL
  );
  </code></pre>
  
  <p>Insert some data (which must have the namespaces as is):</p>
  
  <pre><code>insert into XML_DOCUMENT_TMP
  (document_id,created_date,xml_data)
  values(1,sysdate, 
  '&lt;patent  xmlns="http://schemas.thomson.com/ts/20041221/tsip" 
      xmlns:tsip="http://schemas.thomson.com/ts/20041221/tsip" 
      xmlns:tsxm="http://schemas.thomson.com/ts/20041221/tsxm"  
      tsip:action="replace" tsip:cc="CA" tsip:se="2715340" tsip:ki="C"&gt;
      &lt;accessions tsip:action="replace"&gt;
          &lt;accession tsip:src="wila" tsip:type="key"&gt;CA-2715340-C&lt;/accession&gt;
          &lt;accession tsip:src="tscm" tsip:type="tscmKey"&gt;CA-2715340-C-20150804&lt;/accession&gt;
      &lt;/accessions&gt;
      &lt;claimed tsip:action="replace"&gt;
      &lt;    claimsTsxm tsip:lang="en"&gt;
              &lt;tsxm:heading tsxm:align="left"&gt;We Claim:&lt;/tsxm:heading&gt;
              &lt;claimTsxm tsip:no="1" tsxm:num="1" tsip:type="main"&gt;1.  power.       &lt;/claimTsxm&gt;
        &lt;/claimsTsxm&gt;
    &lt;/claimed&gt;
  &lt;/patent&gt;
  ');
  </code></pre>
  
  <p>Run the <code>XMLQuery</code>:</p>
  
  <p>Note the need for namespace wildcarding is explained <a href="https://stackoverflow.com/questions/38632694/oracle-xmlquery-is-corrupting-the-namespace" title="see here">here</a></p>
  
  <pre><code>WITH tmpTable AS (
  SELECT * FROM XML_DOCUMENT_TMP cm )
  SELECT tt.xml_data ,
  XMLQuery('declare default element namespace  "http://schemas.thomson.com/ts/20041221/tsip";
    declare namespace  tsip="http://schemas.thomson.com/ts/20041221/tsip";
    declare namespace  tsxm="http://schemas.thomson.com/ts/20041221/tsxm"; 
  
  
    return          
    &lt;patent&gt;{$m/*:patent/@*}
    {
      for $i in $m/*:patent/*
          return    $i
    }
    &lt;/patent&gt;' 
          PASSING tt.xml_data as "m"   RETURNING CONTENT) newXml 
   FROM tmpTable tt
   WHERE tt.document_id in (1);
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>&lt;patent xmlns="http://schemas.thomson.com/ts/20041221/tsip" xmlns:tsip="http://schemas.thomson.com/ts/20041221/tsip" tsip:action="replace" tsip:cc="CA" tsip:se="2715340" tsip:ki="C"&gt;
      &lt;accessions xmlns="http://schemas.thomson.com/ts/20041221/tsip" xmlns:tsip="http://schemas.thomson.com/ts/20041221/tsip" tsip:action="replace"&gt;
          &lt;accession tsip:src="wila" tsip:type="key"&gt;CA-2715340-C&lt;/accession&gt;
          &lt;accession tsip:src="tscm" tsip:type="tscmKey"&gt;CA-2715340-C-20150804&lt;/accession&gt;
      &lt;/accessions&gt;
      &lt;claimed xmlns="http://schemas.thomson.com/ts/20041221/tsip" xmlns:tsip="http://schemas.thomson.com/ts/20041221/tsip" tsip:action="replace"&gt;
          &lt;claimsTsxm tsip:lang="en"&gt;
              &lt;tsxm:heading xmlns:tsxm="http://schemas.thomson.com/ts/20041221/tsip" tsxm:align="left"&gt;We Claim:&lt;/tsxm:heading&gt;
              &lt;claimTsxm tsip:no="1" xmlns:tsxm="http://schemas.thomson.com/ts/20041221/tsip" tsxm:num="1" tsip:type="main"&gt;1.  power.&lt;/claimTsxm&gt;
          &lt;/claimsTsxm&gt;
  &lt;/claimed&gt;
  </code></pre>
  
  <p></p>
  
  <p>How do I get rid of the unwanted namespaces created in the accessions and claimed elements.
  Any suggestions appreciated.</p>