xsl:result-document instruction is used to determine where the output of the XSLT processing is added to the HTML of the rendered page.
<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.
<xsl:result-document href="?select=//table/tbody/tr/td"> 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:
All HTML elements and attributes are considered to have lower-case names
For elments in a namespace such as XHTML or SVG, ensure the appropriate namespace context is provided
Mandatory nodes such as
table are implicit within the DOM,
even when not added explicitly
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.
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:remove-attribute can be used. See Extension Instructions
for more detail.