> I am trying to figure out how to load an XQuery module into a static context programmatically.  
 
 
The API isn't designed to enable this: library modules are intended only to be called from main modules, and are loaded automatically when the "import module" declaration is encountered. However, Saxon internally uses the mechanism to support <saxon:import-query>, which allows a query library module to be imported into an XSLT stylesheet.
 
You'll need to use the static loadQueryModule() method in StaticQueryContext (rather than compileQuery), and as you point out, this is written to read the module by dereferencing a URI. Unfortunately there's no URIResolver mechanism for query text, because queries aren't XML. You'll also need to construct an Executable somehow, representing the "host" program that is importing the library module.
 
You could of course copy the logic of loadQueryModule() into your own code: I don't think it uses any methods that have privileged access; you could then modify it to take a string as input.
 
I think my advice would be not to attempt this.
 
What are you actually trying to achieve?
 
Michael Kay