xsl:result-document

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. This 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.

This base output URI must be a writable location, which generally will only be the case when using the "file:/" protocol.

The optional validation and type attributes determines 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.

Expand

Next