XSLT » Functions » document

Syntax:
node-set = document(uri, base-uri)
base-uri
The optional base-uri attribute provides a base URI to help resolve a relative URI provided in the uri attribute. If this argument is the empty string, document(' '), then the root node of the stylesheet from where the function call was made is returned.
uri
The mandatory uri attribute defines the absolute or relative URI for an XML document. If a relative URI is provided, it will be considered relative to the base URI of the stylesheet containing the function call. If this argument is the empty string, document(' '), then the the root node of the stylesheet from where the function call was made is returned. Or, if this argument is the empty string and the function call was made as part of an exported or included stylesheet, then the root node of that exported or included stylesheet is returned.

The document function is used to locate an external XML document, to parse that XML document, and to return a node-set that contains the root node.

It is presumed that the XML document is valid and can be parsed. If the external XML document cannot be located, or the provided URI (Uniform Resources Identifier) is invalid, or the document is not valid XML, then the XSLT processor may either declare an error or return an empty node-set.
 
A fundamental problem is that this function may return a result tree fragment that is not well-formed. (About all that you can do with such a fragment is to convert it to a Boolean or a string.)

Examples

Code:
<xsl:variable name="example" select="document(@href)"> ...
<xsl:apply-template select="document(@text)" /> ...
Explanation:

Here are two examples of the document function.

Language(s): XSLT

See Also: