if ($i <= 1)
then 1
else jnb:fib($i - 1) + jnb:fib($i - 2)
};
(: mainfib.xq: )
import module namespace jnb = "http://ociweb.com/jnb" at "libfib.xq";
jnb:fib(6)
[weiqi@gao] $ xquery mainfib.xq # Saxon
13
Qexo supports compiled modules. A library module is compiled to a Java class whose name is derived from the module namespace URI. A main module is compiled to a Java class whose name is derived from the module file name.
[weiqi@gao] $ qexo -C libfib.xq # Compile to Java class com.ociweb.jnb
(compiling libfib.xq)
[weiqi@gao] $ qexo --main -C mainfib.xq # Compile to Java class mainfib
(compiling mainfib.xq)
[weiqi@gao] $ java mainfib
13
-------------------------------------------------------------------------
Type Specification
XQuery is a strongly typed programming language. Like Java and C#, for example, it's a mix of static typing (type consistency checked at compile-time) and dynamic typing (run-time type tests). However, the types in XQuery are different from the classes familiar from object-oriented programming. Instead, it has types to match XQuery's data model, and it allows you to import types form XML Schema.
if ($child instance of element section)
then process-section($child)
else ( ) {--nothing--}
This invokes the process-section function if the value of $child is an element whose tag name is section. XQuery has a convenient typeswitch shorthand for matching a value against a number of types. The following converts a set of tag names to a different set.
define function convert($x) {
typeswitch ($x)
case element para return <p>{process-children($x)}</p>
case element emph return <em>{process-children($x)}</em>
default return process-children($x)
}
define function process-children($x) {
for $ch in children($x)
return convert($ch)
}
Hello,
I am a beginner in Xquery.