Using a source resolver at execution time
By specifying a source resolver at the time that an executable is being executed, you can tell the processor how to interpret the URIs referenced at that time.
Procedure
This tells the processor how to interpret the URIs referenced at that time, in calls to the fn:doc() or document() functions for example.
The default source-resolution behavior is to interpret relative URIs in terms of the base URI of the expression, query, or stylesheet if the base URI is available or to interpret them as file paths relative to the current working directory if the base URI is not available. Absolute URIs are used unchanged.
To change this behavior, write a Java™ class that implements the XSourceResolver interface and register it with the XDynamicContext before executing the expression, query, or stylesheet.
XFactory factory = XFactory.newInstance();
XStaticContext staticContext = factory.newStaticContext();
// Prepare the stylesheet
XSLTExecutable executable = factory.prepareXSLT(new StreamSource(stylesheetFile), staticContext);
XDynamicContext dynamicContext = factory.newDynamicContext();
// Register the source resolver with the dynamic context
XSourceResolver sourceResolver=new ASourceResolver(replacementBase);
dynamicContext.setSourceResolver(sourceResolver);
// Execute the XPath expression
XSequenceCursor cursor = executable.execute(new StreamSource(inputFile), dynamicContext);