Database Reference
In-Depth Information
If an empty sequence was used for the
greeting
parameter, we fall back to the
default greeting of
hello
.
As our third parameter,
visitors
, is a sequence of one or more values, we obtain
an iterator over the values.
We iterate over each visitor name from
visitors
and add it to our list of visitors.
We call our business logic, which generates a greeting for each visitor.
This is our isolated business logic, which will generate our greetings.
We create a new
ValueSequence
to hold each of the greetings that we wish to
return to the XQuery.
We create a new
StringValue
, which represents an
xs:string
value to hold each
of our greetings.
We add our greeting to the value sequence.
We return the value sequence, which now contains each of our greetings as
strings. This is then returned to the XQuery by the
eval
method.
The source code for this example is included in the
HelloModule
code, as discussed
earlier. To compile and deploy the module, see
“Using the Hello World Module” on
page 473
. To test the example, execute the following XQuery from either eXist's Java
Admin Client (see
“Java Admin Client” on page 373
) or eXide (see
“eXide” on page
374
):
xquery
version
"1.0"
;
declare
namespace
h
=
"http://hello"
;
h:say-hello
(
"Adam"
,
(),
(
"Elisabeth"
,
"David"
))
The result of the query should look similar to:
Adam says hello to Elisabeth
Adam says hello to David
You can experiment with providing different values for the second argument to the
function and observe how the results change.
We have now built an XQuery extension function in Java for our internal module
that can both accept multiple parameters of varying cardinality and return a sequence
of results. Every internal module extension function that is written for XQuery in
eXist follows this same pattern.
Search WWH ::
Custom Search