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
<alexkra...@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

Reply via email to