Saxonica: XSLT and XQuery Processing: Result documents

Result documents

The xsl:result-document instruction is used to determine where the output of the XSLT processing is added to the HTML of the rendered page.

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.

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.