I tried that, I figured it was not supported: [XQST0108] No output declarations allowed in library modules.
True, this is a restriction of the XQuery 3.0 specification. However, output declarations are allowed in main modules, and since 7.7, you can specify your RESTXQ functions both in library and main modules [1].
Hope this helps, Christian