Hello,
writing a RESTXQ application, I have the following code in a module:
module namespace page = 'http://localhost/web-page';
declare %rest:path("/list/{$category}") %rest:GET %rest:query-param("page:category", "{$category}") %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:list($page:category as xs:string) { () };
I get:
[basex:restxq] Variable $category is not specified as argument.
If I replace *every* '$category' with '$page:category' I get:
[basex:restxq] Variable $page:category is specified more than once.
But the only place I use '$page:category' in this module is at this point.
The rules are, as far as I have understood:
1. In a module, only one namespace can be used for the functions and variables defined therein, foreign namespaces can be sourced via module imports only. 2. This namespace can not be in the {http://www.w3.org/2005/xquery-local-functions%7D namespace, but must go into my own namespace, here {http://localhost/web-page%7D. 3. All variables must be in the relevant namespaces *(global or local only?)*.
I now have tried several approaches. As I see in the XQM modules in the BaseX DBA application, it seems, that neither the '%rest:query-param' is needed nor is it needed to prefix variable/parameter names, that are local to that function. This can be found, for example, in 'dba/common.xqm':
module namespace dba = 'dba/common'; (:~ : Shows a "page not found" error. : @param $path path to unknown page : @return page :) declare %rest:path("/dba/{$path}") %output:method("html") function dba:unknown( $path as xs:string ) as element(html) { html:wrap( <tr> <td> <h2>Page not found:</h2> <ul> <li>Page: dba/{ $path }</li> <li>Method: { Request:method() }</li> </ul> </td> </tr> ) };
So, I am disturbed by now. What am I doing wrong here?
Hi Andreas,
%rest:query-param("page:category", "{$category}")
• The first argument is the name of the query parameter how it will be passed on by the client. • The second argument is the name of your XQuery variable
function page:list($page:category as xs:string) { () };
This should work:
function page:list($category as xs:string?) { };
Hope this helps, Christian
[basex:restxq] Variable $category is not specified as argument.
If I replace *every* '$category' with '$page:category' I get:
[basex:restxq] Variable $page:category is specified more than once.
But the only place I use '$page:category' in this module is at this point.
The rules are, as far as I have understood:
- In a module, only one namespace can be used for the functions and variables defined therein, foreign namespaces can be sourced via module imports only.
- This namespace can not be in the {http://www.w3.org/2005/xquery-local-functions%7D namespace, but must go into my own namespace, here {http://localhost/web-page%7D.
- All variables must be in the relevant namespaces *(global or local only?)*.
I now have tried several approaches. As I see in the XQM modules in the BaseX DBA application, it seems, that neither the '%rest:query-param' is needed nor is it needed to prefix variable/parameter names, that are local to that function. This can be found, for example, in 'dba/common.xqm':
module namespace dba = 'dba/common'; (:~ : Shows a "page not found" error. : @param $path path to unknown page : @return page :) declare %rest:path("/dba/{$path}") %output:method("html") function dba:unknown( $path as xs:string ) as element(html) { html:wrap( <tr> <td> <h2>Page not found:</h2> <ul> <li>Page: dba/{ $path }</li> <li>Method: { Request:method() }</li> </ul> </td> </tr> ) };
So, I am disturbed by now. What am I doing wrong here?
-- Goody Bye, Minden jót, Mit freundlichen Grüßen, Andreas Mixich
Hi Andreas,
Sorry, I overlooked that you had already specified the $category variable in your path annotation.
As I see in the XQM modules in the BaseX DBA application, it seems, that neither the '%rest:query-param' is needed
Exactly; it’s only needed if you want to pass on query parameters. The query parameter string starts with the optional question mark in an URL; see e.g.:
https://duckduckgo.com?q=BaseX
If you want to process query parameters, please take care that each annotation variable appears as separate parameter in your declared function. You might want to try the following version:
declare %rest:path("/list/{$category}") %rest:query-param("page:category", "{$page-category}") %output:method("html") function page:list( $page:category as xs:string, $page-category as xs:string? ) { (: etc :) };
Best, Christian
On Fri, Apr 27, 2018 at 11:07 PM, Andreas Mixich mixich.andreas@gmail.com wrote:
Hello Christian,
you wrote:
This should work:
function page:list($category as xs:string?) { };
Thanks, if I remove the 'rest:query-parameter()' annotation it works.
-- Goody Bye, Minden jót, Mit freundlichen Grüßen, Andreas Mixich
basex-talk@mailman.uni-konstanz.de