Result documents

The xsl:result-document instruction is used capture an output tree from the XSLT transformation and to determine where this tree should be added to the HTML of the rendered page.

The recommended design approach with Saxon-CE is not to render the entire HTML page from the stylesheet, but rather to generate fragments of HTML which can be inserted into the static skeleton of the page at the appropriate places.

The form <xsl:result-document href="#abcd"> causes the result tree to be written as the last (or only) child of the HTML element with a given ID value.

The form <xsl:result-document href="?select=//table[1]/tbody/tr[1]/td[2]"> can be used to select the target element. The result tree will be appended as a child of the first selected element. Relative XPaths like ../h1 may be used if the current node is set and is a member of the host HTML document.

Considerations when selecting the HTML target node:

If the href supplied does not match an existing element in the HTML page, the xsl:result-document instruction is ignored and the transform will continue to completion. In this case, Saxon-CE (debug version only) sends a warning message to the development console with information about the failed match.

The method attribute may be one of ixsl:append-content (the default) or ixsl:replace-content. This indicates whether the new content should replace all existing content in the selected element, or should be appended after existing content.

When the xsl:result-document instruction is evaluated, the HTML page is not updated immediately. Instead, the result documents are added to a pending update list, which is used to modify the HTML page when all processing is complete. The stylesheet therefore gets a static view of the HTML page, which is not affected by changes made during that processing phase. Of course, when a new transformation starts in response to user input, the effects of the previous phase are visible.

When HTML page changes are required that only affect attributes, the extension instructions xsl:set-attribute and xsl:remove-attribute can be used. See Extension Instructions for more detail. The effect of these instructions, like xsl:result-document, is also deferred until the transformation is complete.