|
>Home>Learn XQuery> XQuery Tips and Tricks>Function Libraries
Print
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?
|