We wanna test if a function exists with fn:function-lookup
As fn:function-lookup only takes QNames, in some cases the namespace isn’t declared. So unsurprisingly, we get an error FONS0004 No namespace declared for prefix ‘……’
Is there any way to test if the namespace is declared first ?
Thanks a lot, and best regards ! Emmanuel
Hi Emmanuel,
Could you possible give us an example? Do you try to do something like..
function-lookup(xs:QName('pref:ln'))
..and would you like to find out the namespace for the 'pref' prefix?
Best, Christian
On Tue, Feb 10, 2015 at 2:01 PM, Emmanuel Chateau emchateau@laposte.net wrote:
We wanna test if a function exists with fn:function-lookup
As fn:function-lookup only takes QNames, in some cases the namespace isn’t declared. So unsurprisingly, we get an error FONS0004 No namespace declared for prefix ‘……’
Is there any way to test if the namespace is declared first ?
Thanks a lot, and best regards ! Emmanuel
Hi Christian, Here is the example of what we would achieve : https://gist.github.com/emchateau/5d8af7f53d6f346512c1 https://gist.github.com/emchateau/5d8af7f53d6f346512c1 Thanks, Emmanuel and Philippe
Le 10 févr. 2015 à 14:26, Christian Grün christian.gruen@gmail.com a écrit :
to
Emmanuel,
Sorry for letting you wait! I guess you would like to have a function like function-lookup("*:abc") ?
I looked at your example, and I must confirm there is no way to look up functions if the namespace is unknown. I see two ways out:
1. Use inspect:functions() to browse through all statically available functions [1] and choose the ones you need.
2. If you know the namespace in advance, it's possible best to do what you already did: Try to find the custom namespace, and resort to the default if no function is returned. Here is an alternative way to put it:
let $suffix := '.models.' || map:get($queryParams, 'model') || ':' || map:get($queryParams, 'dataType') let $function := ( for $prefix in (map:get($queryParams, 'project'), 'synopsx') return fn:function-lookup($prefix || $suffix, 1) )[1] return xs:QName($function)
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Inspection_Module#inspect:functions
On Tue, Feb 10, 2015 at 2:41 PM, Emmanuel Chateau emchateau@laposte.net wrote:
Hi Christian, Here is the example of what we would achieve :
https://gist.github.com/emchateau/5d8af7f53d6f346512c1
Thanks,
Emmanuel and Philippe
Le 10 févr. 2015 à 14:26, Christian Grün christian.gruen@gmail.com a écrit :
to
An addendum: XQuery 3.1 will provide a new function fn:load-xquery-module [1]. We haven't implemented it so far, as we first need to sort out various questions first. It may also be that the specification changes along with the first implementations. But it may be something similar to what you have been requesting some time ago..
[1] http://www.w3.org/TR/xpath-functions-31/#func-load-xquery-module
On Wed, Feb 11, 2015 at 7:41 AM, Christian Grün christian.gruen@gmail.com wrote:
Emmanuel,
Sorry for letting you wait! I guess you would like to have a function like function-lookup("*:abc") ?
I looked at your example, and I must confirm there is no way to look up functions if the namespace is unknown. I see two ways out:
- Use inspect:functions() to browse through all statically available
functions [1] and choose the ones you need.
- If you know the namespace in advance, it's possible best to do what
you already did: Try to find the custom namespace, and resort to the default if no function is returned. Here is an alternative way to put it:
let $suffix := '.models.' || map:get($queryParams, 'model') || ':' || map:get($queryParams, 'dataType') let $function := ( for $prefix in (map:get($queryParams, 'project'), 'synopsx') return fn:function-lookup($prefix || $suffix, 1) )[1] return xs:QName($function)
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Inspection_Module#inspect:functions
On Tue, Feb 10, 2015 at 2:41 PM, Emmanuel Chateau emchateau@laposte.net wrote:
Hi Christian, Here is the example of what we would achieve :
https://gist.github.com/emchateau/5d8af7f53d6f346512c1
Thanks,
Emmanuel and Philippe
Le 10 févr. 2015 à 14:26, Christian Grün christian.gruen@gmail.com a écrit :
to
Thanks a lot ! It helps really (as you do always). Emmanuel
Le 11 févr. 2015 à 09:01, Christian Grün christian.gruen@gmail.com a écrit :
An addendum: XQuery 3.1 will provide a new function fn:load-xquery-module [1]. We haven't implemented it so far, as we first need to sort out various questions first. It may also be that the specification changes along with the first implementations. But it may be something similar to what you have been requesting some time ago..
[1] http://www.w3.org/TR/xpath-functions-31/#func-load-xquery-module
On Wed, Feb 11, 2015 at 7:41 AM, Christian Grün christian.gruen@gmail.com wrote:
Emmanuel,
Sorry for letting you wait! I guess you would like to have a function like function-lookup("*:abc") ?
I looked at your example, and I must confirm there is no way to look up functions if the namespace is unknown. I see two ways out:
- Use inspect:functions() to browse through all statically available
functions [1] and choose the ones you need.
- If you know the namespace in advance, it's possible best to do what
you already did: Try to find the custom namespace, and resort to the default if no function is returned. Here is an alternative way to put it:
let $suffix := '.models.' || map:get($queryParams, 'model') || ':' || map:get($queryParams, 'dataType') let $function := ( for $prefix in (map:get($queryParams, 'project'), 'synopsx') return fn:function-lookup($prefix || $suffix, 1) )[1] return xs:QName($function)
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Inspection_Module#inspect:functions
On Tue, Feb 10, 2015 at 2:41 PM, Emmanuel Chateau emchateau@laposte.net wrote:
Hi Christian, Here is the example of what we would achieve :
https://gist.github.com/emchateau/5d8af7f53d6f346512c1
Thanks,
Emmanuel and Philippe
Le 10 févr. 2015 à 14:26, Christian Grün christian.gruen@gmail.com a écrit :
to
basex-talk@mailman.uni-konstanz.de