4.6 in the XQuery spec says:
If the variable definition includes the keyword external,
a value must be provided for the variable by the external
environment before the query can be evaluated.
This does not provide a mechanism for providing a default
value to an optional parameter. Admittedly an implementation
can implement a convention, such as a missing parameter
resulting in an empty sequence. However, the XSLT spec
does specify that parameters may be optional, and for
consistency the XQuery spec should do the same.
Here are two options that come to mind:
(1) Don't change the syntax. However, if the type of the
variable (either the default of 'item*' or an explicit
TypeDeclaration) has an OccurrenceIndicator or '?' or '*',
then a missing parameter results in the empty sequence.
Otherwise a type error is raised.
(2) Use an explicit syntax. I suggest:
define variable $VarName [as Type] external { default-expression }
define variable $VarName [as Type] external required
The former specifies that the parameter is optional and gives a
default value; the latter specifies that the parameter is required.
I think (2) is the better solution.
--
--Per Bothner
per@bothner.com http://per.bothner.com/