Hi Jörn,

The behavior is compliant with the spec: The default namespace of node tests in path expressions is affected by default namespace declarations (xmlns="") appearing on element constructors.

You can achieve the expected result by using wildcards or the "Q{uri}local" syntax in the path…

  $w/*:title/text()
  $w/Q{}title/text()

…or by moving the path outside the element constructor.

With XQuery 4 (as indicated by Martin), it will be possible to change the default behavior by introducing the query with a declaration that changes the default behavior:

declare fixed default element namespace '';

This syntax will be supported in one of the next versions of BaseX.

Best, 
Christian



Jörn Willhöft <jwi@willhoeft-it.com> schrieb am Do., 9. Jan. 2025, 19:23:
Hi all,
 
I just come across an issue, and I am not sure if I am too stupid to see the mistake, or it is a bug in BaseX.
 
I need to create an XML document from data in BaseX 11.5 inside basexgui. The data in the database does not use any namespaces. The document I am creating must have a default namespace set. Here is a stripped down example of my XQuery:
 
for $w in /json/workouts/_/header[uuid='123'] return
<gpx xmlns="http://www.topografix.com/GPX/1/1" >
  <title>{$w/title/text()}</title>
</gpx>
 
Strangely all XPaths inside and outside the gpx-element will not match anything as long as I have the default namespace on the gpx-element defined. It works if I drop the xmlns attribute or I define the namespace explicitly, like:
 
for $w in /json/workouts/_/header[uuid='123'] return
<g:gpx xmlns:g="http://www.topografix.com/GPX/1/1" >
  <g:title>{$w/title/text()}</g:title>
</g:gpx>
 
Even though this should be semantically equal to the output of the above, the third party app that I import this to does not recognize it as such.
 
This is puzzling me mainly because I do not see, why the namespace I define for the *output* xml should have an impact on the queries that are directed to my database. As a workaround I will probably use a regex to remove the namespace, but that's obviously pretty awkward.
 
Any ideas?
 
Cheers
   Jörn