Am 25.08.2021 um 15:12 schrieb Yann NICOLAS (ABES):

Hi all,

I am looking for the equivalent instruction of XSLT attribute @omit-xml-declaration in XQuery.


In the Query prolog you can declare


declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option output:method 'xml';
declare option output:omit-xml-declaration 'yes';



My input is :

<marc>
  <marc:record xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <marc:leader>01321nam a22002772a 4500</marc:leader>
    <c level="item">
      <did>
        <unitid type="division">1808001595</unitid>
      </did>
    </c>
  </marc:record>
<marc>

My query is :

declare namespace marc="http://www.loc.gov/MARC21/slim";

for $record in db:open('marcxml_full')/marc/marc:record
return
insert node $record/c into db:open('uk_parlement_ead')/dsc
The ouput is :

<c xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" level="item">
      <did>
        <unitid type="division">1808001595</unitid>
      </did>
    </c>
As you can see, there are no marc: elements in this output, hence no need for the marc: namespace.
How to get rid of @xmlns:marc and xmlns:xsi ?


That seems to be a different issue from the XML declaration, if the nodes you copy from the one db into the other have a namespace in scope than that namespace is copied through.

Perhaps

   insert node $record/c ! element { node-name() } {  @*, node() } into db:open('uk_parlement_ead')/dsc

does what you need.