[xquery-talk] best practice for function design with many optional params

Michael Kay mike at saxonica.com
Thu Jan 26 01:13:06 PST 2012

On 26/01/2012 08:13, Jakob Fix wrote:
> Hello,
> I'm confronted with the design of a function library where many
> functions have loads of optional arguments.
> I haven't really looked at maps (they are planned for XQuery 3.0 I
> think), what would their advantage be over the node approach? Any
> other ideas or pointers for more information?
Maps provide a good solution to this requirement, but sadly there has 
been resistance to getting them into the XQuery language in 3.0 
timescales so you may have to wait a little longer. (Or, as with 
grouping and updates, hope that your chosen implementors are ahead of 
the standards curve.)

If the optional parameters have values that are single strings, passing 
an element node with lots of attributes provides a suitable solution 
(it's equivalent to a map whose keys are QNames and whose associated 
values are strings). For more complex parameters this starts to break 
down, for example you can't pass nodes or function items this way. The 
other disadvantage of using nodes is that they carry a lot of baggage - 
identity, base URI, in-scope namespaces - which add cost and complexity 
without being in any way useful for this use case.

Michael Kay

More information about the talk mailing list