WAS v8.5 > Develop applications > XML applications > Use the XML API to perform operations > Use resolvers > Use source and result resolvers

Use a source resolver at prepare time

By specifying a source resolver at the time that an executable is being prepared, we can tell the processor how to interpret the URIs referenced at that time.

Specify a source resolver at the time an executable is being prepared.

This tells the processor how to interpret the URIs referenced at that time, in a stylesheet's xsl:import and xsl:include directives 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 XStaticContext before preparing the stylesheet.

The following is a basic example of how to register the source resolver.

XFactory factory = XFactory.newInstance();

// Register the source resolver with the static context XStaticContext staticContext = factory.newStaticContext();
XSourceResolver sourceResolver=new ASourceResolver(replacementBase);
staticContext.setSourceResolver(sourceResolver);

// Prepare the sylesheet
XSLTExecutable executable = factory.prepareXSLT(new StreamSource(stylesheetFile), staticContext);

XDynamicContext dynamicContext = factory.newDynamicContext();

// Execute the stylesheet
XSequenceCursor cursor = executable.execute(new StreamSource(inputFile), dynamicContext);


+

Search Tips   |   Advanced Search