Functions

The XQuery language supports declaring functions and grouping them together in library modules. As your code grows more complex this helps keep it manageable. Here's the above query rewritten to use some local functions (which use the "local" namespace) to build the query piece-by-piece. Notice there's typing information for variables and return values. That's optional but usually a good idea. Each type accepts a modifier the same as in regular expressions: asterisk means 0 to n many, question mark means 0 or 1, plus means 1 to n many, and no modifier means exactly one.

To break functions into library modules you put them in a separate file and give them a special header. Here's file test-lib.xqy (which is already installed on the box for you):

And here's how you import the library and use it:

Search Relevance

Query-Limited Facets

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.