Resolving the URIs of Output Files

Saxon 9.9 introduces a new mechanism for handling the URIs of output documents specified in the @href attribute of xsl:result-document.

Various interfaces, such as the s9api Xslt30Transformer, have a method setResultDocumentHandler() which accepts a Java Function<URI, Destination>, that is, a function that accepts an absolute URI and returns a Destination for the output. For example, you might write:

transformer.setResultDocumentHandler(uri -> processor.newSerializer(....))

When writing to the secondary result document is complete, Saxon will call the method Destination.close(), whose effect depends on the kind of destination. For example, in the case of a Serializer, the close() method will close any input stream that Saxon created, but not one that the user created, unless the method Serializer.setCloseOnCompletion() is called to request this.

You can also call the method Destination.onClose() to supply an application-specific action to be performed when the destination is closed. For example, if the URI is a mailto: URI, you might want to attach the serialized result to an email message and send it to a nominated recipient.

The older OutputURIResolver mechanism is retained for backwards compatibility. This is limited by the fact that it returns a JAXP Result object, which doesn't allow, for example, for returning a "raw" result in which the XSLT results are not wrapped in a document node.

There is a change in Saxon 9.9 regarding the way in which an xsl:result-document instruction with no href attribute is handled. In previous releases Saxon attempted to reuse the output stream established for the primary output of the transformation. The new XSLT 3.0 options (such as raw output) make this difficult, and possibly non-conformant. The new model is therefore that the href attribute simply defaults to the base output URI, and is otherwise handled in the same way as any other call on xsl:result-document. The main difference will be noticed if no base output URI is supplied, which will now cause a failure.