Name
[2.0] collection()
Returns a collection of nodes. This expands on the
capabilities of the document() function defined in XSLT
1.0.
Syntax
node()*collection(xs:string?)
Input
An optional xs:string
specifying the URI of a collection. If no string is given, the
default collection is returned.
Output
The specified collection of nodes. If no collection name is given, the default collection is returned. The details of the URI format and what kinds of resources can be accessed are implementation-dependent.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.5, “Functions and Operators that Generate Sequences.”
Example
For our example, we’ll use Saxon’s implementation that allows us to load an XML document referencing other XML documents. The structure of the collection document is:
<?xml version="1.0"?>
<!-- polist.xml -->
<collection>
<doc href="po38292.xml"/>
<doc href="po38293.xml"/>
<doc href="po38294.xml"/>
<doc href="po38295.xml"/>
</collection>When loading this document with the collection() function, Saxon looks
at the href attributes of all
the <doc> elements and
considers each one a document URI. Saxon then opens and parses
those documents and adds their nodes to the collection. Each
document URI in our example points to a purchase order document
structured like this:
<?xml version="1.0" ?>
<!-- po38293.xml --> <purchase-order id="38293"> <date year="2001" month="9" day="8"/> <customer id="4738" level="Basic"> <address type="business"> <name> <title>Ms.</title> <first-name>Amanda</first-name> ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access