Invoking the document() Function

In our previous stylesheet, we used the document() function to select some number of nodes from the original source document (our list of purchase orders), then open those files. There are a number of ways to invoke the document() function; we’ll discuss them briefly here.

The most common way to use the document() function is as we just did. We use an XPath expression to describe a node-set; the document() function takes each node in the node-set, converts it to a string, then uses that string as a URI. So, when we passed a node-set containing the filename attributes in the list of purchase orders, each one is used as a URI. If those URIs are relative references (i.e., they don’t begin with a protocol like http), the base URI of the stylesheet is used as the base URI for the reference.

If the document() function has two arguments, the second must be a node-set. The first argument is processed as just described, with the difference that the base URI of the first node in the node-set is used as the base URI for any relative URIs. That combination isn’t used often, but it’s there if you need it.

Note

Every node in the XPath source tree is associated with a base URI. When using the document() function, the base URI is important for resolving references to various resources (typically specified with relative links in a file opened with the document() function.

If a given node is an element or processing instruction node, and that node occurs in an external ...

Get XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.