Changes

Jump to navigation Jump to search
238 bytes added ,  15:30, 27 February 2020
no edit summary
|'''Examples'''
|Invokes the declared functions and returns their values:<br/>
<pre classsyntaxhighlight lang="brush:xquery">
declare %private function local:one() { 12 };
declare %private function local:two() { 34 };
for $f in inspect:functions() return $f()
</presyntaxhighlight>
Compiles all functions in {{Code|code.xqm}} and invokes the function named {{Code|run}}:
<pre classsyntaxhighlight lang="brush:xquery">
let $uri := 'code.xqm'
let $name := "run"
where local-name-from-QName(function-name($f)) = $name
return $f()
</presyntaxhighlight>
|}
|
* Returns an empty map:
<pre classsyntaxhighlight lang="brush:xquery">
inspect:function-annotations(true#0)
</presyntaxhighlight>
* 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:
<pre classsyntaxhighlight lang="brush:xquery">
declare %private function local:f() { 'well hidden' };
inspect:function-annotations(local:f#0)
</presyntaxhighlight>
|}
|
* Returns the static base URI (same as {{Code|static-base-uri()}}):
<pre classsyntaxhighlight lang="brush:xquery">
inspect:static-context((), 'base-uri')
</presyntaxhighlight>
* Returns a map with all namespaces that are statically known in the module of the specified function:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace data = 'data.xqm';
inspect:static-context(data:get#1, 'namespaces')
</presyntaxhighlight>
|-
| '''Errors'''
|'''Examples'''
|The query {{Code|inspect:function(count#1)}} yields:
<pre classsyntaxhighlight lang="brush:xml">
<function name="count" uri="http://www.w3.org/2005/xpath-functions" external="false">
<argument type="item()" occurrence="*"/>
<return type="xs:integer"/>
</function>
</presyntaxhighlight>
The function…
<pre classsyntaxhighlight lang="brush:xquery">
(:~
: This function simply returns the specified integer.
$number
};
</presyntaxhighlight>
…is represented by {{Code|inspect:function(local:same#1)}} as…
<pre classsyntaxhighlight lang="brush: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>
</presyntaxhighlight>
|}
| '''Examples'''
|Evaluate all user-defined functions with zero arguments in the query context:<br/>
<pre classsyntaxhighlight lang="brush:xquery">
inspect:context()/function ! function-lookup(QName(@uri, @name), 0) ! .()
</presyntaxhighlight>
Return the names of all private functions in the current context:
<pre classsyntaxhighlight lang="brush:xquery">
for $f in inspect:context()/function
where $f/annotation/@name = 'private'
return $f/@name/string()
</presyntaxhighlight>
|}
This is the {{Code|sample.xqm}} library module:
<pre classsyntaxhighlight lang="brush:xquery">
(:~
: This module provides some sample functions to demonstrate
$number
};
</presyntaxhighlight>
If {{Code|inspect:module('sample.xqm')}} is run, the following output will be generated:
<pre classsyntaxhighlight lang="brush:xml">
<module prefix="samples" uri="http://basex.org/modules/samples">
<description>This module provides some sample functions to demonstrate
</function>
</module>
</presyntaxhighlight>
The output looks as follows if {{Code|inspect:xqdoc('sample.xqm')}} is called:
<pre classsyntaxhighlight lang="brush:xml">
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
</xqdoc:functions>
</xqdoc:xqdoc>
</presyntaxhighlight>
=Errors=
Bureaucrats, editor, reviewer, Administrators
12,957

edits

Navigation menu