Changes

Jump to navigation Jump to search
673 bytes removed ,  18:39, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
This [[Module Library|XQuery Module]] contains functions for extracting internal information about modules and functions and generating documentation.
 
With {{Announce|Version 11}}, {{Code|inspect:function-annotations}} has been removed as it is now available in the official specification as [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-function-annotations <code>fn:function-annotations</code>].
=Conventions=
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:functions(
$uri href as xs:string := ()
) as function(*)*</pre>
|- valign="top"
| '''Summary'''
|Returns function items for all user-defined functions (both public and private) that are known in the current query context. If a an {{Code|$urihref}} value is specified, the specified resource will be retrieved as a string and compiled, and its functions will be added to the query context and returned to the user. A relative URI will be resolved against the static base URI of the query.
|- valign="top"
|'''Examples'''
|Invokes the declared functions and returns their values:<br/>
<syntaxhighlight pre lang="'xquery"'>
declare %private function local:one() { 12 };
declare %private function local:two() { 34 };
for $f in inspect:functions() return $f()
</syntaxhighlightpre>
Compiles all functions in {{Code|code.xqm}} and invokes the function named {{Code|run}}:
<syntaxhighlight pre lang="'xquery"'>
let $uri := 'code.xqm'
let $name := 'run'
where local-name-from-QName(function-name($f)) = $name
return $f()
</syntaxhighlightpre>
|- valign="top"
| '''Errors'''
|{{Error|parse|#Errors}} Error while parsing a module.
|}
 
==inspect:function-annotations==
 
{| width='100%'
|- valign="top"
| width='120' | '''Signatures'''
|<pre>inspect:function-annotations(
$function as function(*)?
) as map(xs:QName, xs:anyAtomicType*)</pre>
|- valign="top"
| '''Summary'''
|Returns the annotations of the specified {{Code|$function}} in a map.
|- valign="top"
| '''Examples'''
|
* Returns an empty map:
<syntaxhighlight lang="xquery">
inspect:function-annotations(true#0)
</syntaxhighlight>
* Returns a map with a single key <code><nowiki>Q{http://www.w3.org/2012/xquery}private</nowiki></code> and an empty sequence as value:
<syntaxhighlight lang="xquery">
declare %private function local:f() { 'well hidden' };
inspect:function-annotations(local:f#0)
</syntaxhighlight>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:static-context(
$function as function(*)?,
$name as xs:string
) as item()*</pre>
|
* Returns the static base URI (same as {{Code|static-base-uri()}}):
<syntaxhighlight pre lang="'xquery"'>
inspect:static-context((), 'base-uri')
</syntaxhighlightpre>
* Returns a map with all namespaces that are statically known in the module of the specified function:
<syntaxhighlight pre lang="'xquery"'>
import module namespace data = 'data.xqm';
inspect:static-context(data:get#1, 'namespaces')
</syntaxhighlightpre>
|- valign="top"
| '''Errors'''
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:type(
$value input as item()*, $options as map(*) ? := ()map { }
) as xs:string</pre>
|- valign="top"
| '''Summary'''
|Returns a string representation of the type of a the given {{Code|$valueinput}}:
* The string includes the occurrence indicator.
* The type of functions and nodes may be stricter than the returned type.
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:function(
$function as function(*)
|'''Examples'''
|The query {{Code|inspect:function(count#1)}} yields:
<syntaxhighlight pre lang="xml">
<function name="count" uri="http://www.w3.org/2005/xpath-functions" external="false">
<argument type="item()" occurrence="*"/>
<return type="xs:integer"/>
</function>
</syntaxhighlightpre>
The function…
<syntaxhighlight pre lang="'xquery"'>
(:~
: This function simply returns the specified integer.
$number
};
</syntaxhighlightpre>
…is represented by {{Code|inspect:function(local:same#1)}} as…
<syntaxhighlight pre lang="xml">
<function name="local:same" uri="http://www.w3.org/2005/xquery-local-functions" external="false">
<argument type="xs:integer" name="number">number to return</argument>
<return type="xs:integer">specified number</return>
</function>
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:context() as element(context)</pre>
|- valign="top"
| '''Examples'''
|Evaluate all user-defined functions with zero arguments in the query context:<br/>
<syntaxhighlight pre lang="'xquery"'>
inspect:context()/function ! function-lookup(QName(@uri, @name), 0) ! .()
</syntaxhighlightpre>
Return the names of all private functions in the current context:
<syntaxhighlight pre lang="'xquery"'>
for $f in inspect:context()/function
where $f/annotation/@name = 'private'
return $f/@name/string()
</syntaxhighlightpre>
|}
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:module(
$uri as xs:string
{| width='100%'
|- valign="top"
| width='120' | '''SignaturesSignature'''
|<pre>inspect:xqdoc(
$uri as xs:string
This is the {{Code|sample.xqm}} library module:
<syntaxhighlight pre lang="'xquery"'>
(:~
: This module provides some sample functions to demonstrate
$number
};
</syntaxhighlightpre>
If {{Code|inspect:module('sample.xqm')}} is run, the following output will be generated:
<syntaxhighlight pre lang="xml">
<module prefix="samples" uri="http://basex.org/modules/samples">
<description>This module provides some sample functions to demonstrate
</function>
</module>
</syntaxhighlightpre>
The output looks as follows if {{Code|inspect:xqdoc('sample.xqm')}} is called:
<syntaxhighlight pre lang="xml">
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
</xqdoc:functions>
</xqdoc:xqdoc>
</syntaxhighlightpre>
=Errors=
=Changelog=
 
;Version 11.0
* Removed: {{Code|inspect:function-annotations}}
;Version 9.6
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu