Tamino XQuery User Guide - Software AG Documentation
Tamino XQuery User Guide - Software AG Documentation
Tamino XQuery User Guide - Software AG Documentation
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Advanced Usage<br />
module namespace tree="http://www.examples.com/tree"<br />
declare function tree:depth($e as node()) as xs:integer<br />
{<br />
if (not($e/*))<br />
then<br />
1<br />
else<br />
max(for $c in $e/* return tree:depth($c)) + 1<br />
}<br />
declare function tree:siblings($a as element()) as element()*<br />
{<br />
for $x in $a/../*<br />
where not($x is $a)<br />
return $x<br />
}<br />
Before you can use the functions defined in a library module, you must store the module at a<br />
special place to make it directly accessible to the <strong>XQuery</strong> processor. In <strong>Tamino</strong>, modules are stored<br />
in the system collection ino:source. From a module definition, some meta data is derived to<br />
provide access to module properties that are relevant for efficient lookup of modules and userdefined<br />
functions. The meta data also simplifies querying module properties in order to generate<br />
interface descriptions such as WSDL definitions.<br />
Modules are stored as non-XML data in the ino:module doctype of the ino:source collection.<br />
This way you can define modules using the _process command and remove them with _delete.<br />
Alternatively, you can use the <strong>Tamino</strong> Interactive Interface.<br />
Note that a library module must not contain variable declarations. Also, <strong>Tamino</strong> query pragmas<br />
which are directives to the query processor are not allowed.<br />
To use a module, you must import it with an import statement. Consider using the library of tree<br />
functions:<br />
import module namespace tree="http://www.examples.com/tree"<br />
let $a := foo bar <br />
return tree:siblings($a/a1)<br />
This import statement imports the module with the target namespace http://www.examples.com/tree.<br />
Note that you cannot import the same module more than once.<br />
To check for existing modules, you can query the ino:source collection in the following way to<br />
retrieve the non-XML data of all modules of a given namespace:<br />
<strong>XQuery</strong> <strong>User</strong> <strong>Guide</strong><br />
79