Standard XQuery function set is good enough for common purpose tasks. But what if we need some new functionality not covered by standard set? We just need to implement an XQuery function which will do what we need and place it in extension module for common access. Then the function can be used from any client- or server-side XQueries with no restrictions (or, do we have some cases when such restriction would be useful? Let’s discuss it on our forum then!).
When the absent functionality does not fit well in XQuery domain then use Java! Just implement it as a Java static method in some class, build the library and register jar with its function(s) in the system. Static methods of standard Java SE classes does not require any implementation, just register them as in this sample..