Implementation of document().
The XSLT 1.0 document function returns the root node of a single
XML document or of the union of multiple XML documents. The
arguments are reduced to a set of URIs that indicate the documents
to parse.
The first argument is required and provides a set of URI
references, each of which may be absolute or relative. If it
is a node-set, then the URI references are the string-values of
each node in the set. If the argument is any other kind of
object, the URI reference is the string-value of object.
The second argument is optional. If given, it provides a base URI
for normalizing relative URI references, it must be a node-set,
and only its first node (in document order) is used. The base URI
for all relative references is the URI of the entity from which
the node originated. If the node-set is empty, an exception is
raised (see XSLT 1.0 erratum E14).
If the second argument is not given, then the base URI depends on
whether the first argument is a node-set. If the first argument is
a node-set, then the base URI for each node in the set is the
entity from which that node originated. Otherwise, the base URI is
the URI of the entity containing the node with the document() call
(this URI is usually that of the stylesheet itself, but could be
an imported stylesheet or even a parsed general entity).
Thus,
document('') typically refers to the stylesheet itself, prior to
whitespace stripping;
document('http://somehost/foo.xml') refers to the document at
that absolute URI;
document('foo.xml') typically refers to the foo.xml document
relative to the stylesheet;
document('http://somehost/foo.xml', $ns) where $ns is a non-empty
node-set refers to the document at that absolute URI ($ns is
ignored);
document('foo.xml', $ns) where $ns is a non-empty node-set refers
to the foo.xml document relative to the URI of the entity from
which $ns[1] originated;
document($ns) where $ns is a non-empty node-set is treated as if
it were
document(string($ns[1]),$ns[1])|document(string($ns[2]),$ns[2])
and so on; and
document($ns, $ns2) where $ns is a node-set and $ns2 is a
non-empty node-set is treated as if it were
document(string($ns[1]),$ns2[1])|document(string($ns[2]),$ns2[1])
and so on.