N. America: 800 876 3101 | World: 44 (0) 1753 218 930

Can I create a library of XQuery functions?

Yes! In fact, a library of external XQuery functions is a great way to avoid having to redefine functions in the prologs of every query you write.

You can use the “import module” directive in XQuery; for example, suppose you have defined a library of functions like myFunctions.xquery:

module namespace utilities = "myUtilities";

declare function utilities:getName($book) as xs:string {
 …
};

declare function utilities:getPublisher($book) as xs:string {
 …
};

You can then use the functions defined in that module in any other XQuery doing:

import module namespace utilities = "myUtilities" at "myFunctions.xquery";

for $aBook in doc("books.xml")//book
return utilities:getName($aBook)


Next Question!

How can I query all documents in a folder?

Submit Your DataDirect XQuery Tip or Trick

Tell us your XQuery Tip or Trick – if it gets published on our site, you’ll receive a

$10.00 Amazon.com
Gift Certificate!

Submit your tip or trick today.