Is that a BaseX-specific feature?
I’d say it’s more the rule than the exception that the namespaces of the source and target documents differ, so making the declared default namespace on a direct element constructor the default element namespace for expressions inside isn’t that helpful.
If I use an element constructor like this:
element Q{http://www.w3.org/1999/xhtml%7Dhtml { <body> Database creation date: {db:info($db)/databaseproperties/timestamp/text()}<br/> </body> }
there is no need to use Q{}timestamp or *:timestamp in the expression.
Shouldn’t computed element constructors and direct element constructors be equivalent?
Gerrit
On 27.03.2023 15:54, Christian Grün wrote:
Hi Alex,
You’ve stumbled upon a hidden XQuery feature: If you declare a default namespace in a node constructor…
<html xmlns="http://www.w3.org/1999/xhtml">
…and if you perform a path expression somewhere within that constructor, the default namespace in that scope will be applied to your path. You can circumvent this by either moving the path expression outside the constructor…
let $ts := db:info($db)//timestamp/text() return <html xmlns="http://www.w3.org/1999/xhtml"> <body> Database creation date: { $ts }<br/> </body>
</html>
…or by overwriting the default namespace:
Database creation date: { db:info($db)//Q{}timestamp/text() }<br/>
Hope this helps, Christian
On Mon, Mar 27, 2023 at 3:42 PM Alexander Krasnogolowy alexkrasno@hotmail.com wrote:
Hi,
given the following RESTXQ function: declare %rest:path("/myrest/{$db}") %rest:GET %output:method("xhtml") %output:omit-xml-declaration("no") %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN") %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") function page:html($db as xs:string) {
<html xmlns="http://www.w3.org/1999/xhtml"> <body> Database creation date: {db:info("NB")/databaseproperties/timestamp/text()}<br/> </body> </html> };
The website returns "Database creation date: " (without a timestamp)
If I put that into a function: declare function page:getDBTimestamp($db as xs:string) { db:info($db)/databaseproperties/timestamp/text() };
and call it in the page: <body> Database creation date: {page:getDBTimestamp($db)}<br/> </body>
then I can see the timestamp.
Can somebody explain to my why it makes a difference and why I cannot query the database directly from the RESTXQ function?
Alex