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>
let $doc := document {When I run this in the BaseX GUI, I get
<json>
<workouts>
<_>
<header>
<uuid>123</uuid>
<title>title 1</title>
</header>
</_>
<_>
<header>
<uuid>123</uuid>
<title>title 2</title>
</header>
</_>
</workouts>
</json>
}
let $gpx1 :=
for $w in $doc/json/workouts/_/header[uuid='123']
let $title := $w/title/text()
return
<gpx xmlns="http://www.topografix.com/GPX/1/1" >
<title>{$w/title/text()}</title>
<titlex>{$w/*:title/text()}</titlex>
<titley>{$title}</titley>
</gpx>
let $gpx2 :=
for $w in $doc/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>
return
( $gpx1
, $gpx2
)
<gpx xmlns="http://www.topografix.com/GPX/1/1"><title/><titlex>title 1</titlex><titley>title 1</titley></gpx>The default namespace on <gpx> becomes the default namespace in the XPath expression.
<gpx xmlns="http://www.topografix.com/GPX/1/1"><title/><titlex>title 2</titlex><titley>title 2</titley></gpx>
<g:gpx xmlns:g="http://www.topografix.com/GPX/1/1"><g:title>title 1</g:title></g:gpx>
<g:gpx xmlns:g="http://www.topografix.com/GPX/1/1"><g:title>title 2</g:title></g:gpx>