| SAXONICA | 
The xsl:result-document element is new in XSLT 2.0, and replaces the previous extension element
            saxon:output. It is used to direct output to a secondary output destination. 
         
The format attribute is optional. If present,
            it gives the name of an xsl:output element that describes the serialization
            format for this output document; if absent, the unnamed xsl:output declaration
            is used.
         
The href attribute gives the URI for the result document. If this is a relative
            URI, it is interpreted relative to the base output URI. The base output URI is the systemID of the Result object
            supplied as the destination for the transformation, or if you are using the command line, the value
            of the -o flag. If the href attribute is omitted, the document is written
            to the location identified by the base output URI: this will only work if all the output produced
            by the stylesheet is within the scope of an xsl:result-document instruction.
         
If the base output URI is not known, then the current directory is used, unless the configuration disables calling of extension functions, in which case it is assumed that the stylesheet is not trusted to overwrite files relative to the current directory, and an error is then reported.
This base output URI must be a writable location. Usually it will therefore be a URI that uses the "file:" scheme. However, Saxon attempts to open a connection whatever URI scheme is used, and it should therefore work with any URI where the Java VM has the capability to open a writable connection. Users have reported success in using "ftp:" and "mailto:" URIs.
The optional validation and type attributes determine what
            happens to any type annotations on element or attribute nodes. These values must not be used in 
            the basic Saxon product.
         
The xsl:result-document instruction may also take
            serialization attributes such as method, indent, or saxon:indent-spaces.
            These attributes may be AVTs, so the values can be decided at run-time. Any values specified on the
            xsl:result-document instruction override the values specified on the xsl:output
            declaration.
         
Here is an example that uses xsl:result-document:
<xsl:template match="preface">
    <xsl:result-document href="{$dir}/preface.html" method="html">
        <html><body bgcolor="#00eeee"><center>
            <xsl:apply-templates/>
        </center><hr/></body></html>
    </xsl:result-document>
    <a href="{$dir}/preface.html">Preface</a>
</xsl:template>Here the body of the preface is directed to a file called preface.html (prefixed by a constant that supplies the directory name). Output then reverts to the previous destination, where an HTML hyperlink to the newly created file is inserted.