Using a result resolver at execution time

By specifying a result resolver at execution time, you can tell the processor how to redirect output URIs specified in the executable.

Procedure

To activate a result resolver, register it with the dynamic context before calling execute().

Result resolvers perform essentially the same function as source resolvers, but on the output side of the processor. They allow you to intercept and redirect output URIs specified in the executable, such as xsl:result-document directives in a stylesheet.

The default resolution behavior is to use the base output URI to resolve result documents if the URI reference is relative. Absolute URIs are used unchanged.

The following is a basic example of a result resolver.
class AResultResolver implements XResultResolver
{
    String _replacementBase;
    
    public AResultResolver(String replacementBase)
    {
    		_replacementBase=replacementBase;
    }
    
    // Resolve URIs by loading the resource as an XSLT stylesheet
    // and evaluating it - return the result as the Source to use
    public Result getResult(String href, String base) {
    		String rebasePrefix="rebase://";
    
    		if(href.startsWith(rebasePrefix))
    		{
    			href=href.substring(rebasePrefix.length());
    			base=_replacementBase;
    		}

    		java.net.URI baseURI;
    		Result result=null;
    		try {
      			// Get base URI object
    	   		baseURI = new java.net.URI(base);
        		// Resolved relative reference against base URI
        		URI resolvedURI = baseURI.resolve(href);
        		// Try to read...
        		result = new StreamResult(resolvedURI.toString());
    		} catch (java.net.URISyntaxException use) {
    		   	throw new RuntimeException(use);
			  }

    		return result;
    }
}  
The following is a basic example of registering and using the resolver.
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 result resolver with the dynamic context
XResultResolver resultResolver=new AResultResolver(replacementBase);
dynamicContext.setResultResolver(resultResolver);

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



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms of Use | Feedback

Last updatedLast updated: Sep 19, 2011 6:15:55 PM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=matt&product=was-express-dist&topic=txml_resolvers_result_exec
File name: txml_resolvers_result_exec.html