[2.0] The doc() and doc-available() Functions

XSLT 2.0 provides a new function, doc(), that is very similar to the document() function, but that is simpler in a couple of ways. First of all, the document() function can take a node-set or sequence as its first argument, whereas doc() takes a single string. In our earlier stylesheets, we created a variable containing all of the nodes from all of the documents referenced in our list of purchase orders:

<xsl:variable name="purchase-orders"

This returns a sequence of purchase-order nodes, each of which has the structure defined in the purchase order. We can use the variable $purchase-orders in an <xsl:for-each> or <xsl:for-each-group> element. A stylesheet that contains this markup raises an error if there is more than one <po> element in the source document:

<!-- This doesn't work with our sample document -->
<xsl:variable name="purchase-orders"

If we want to use the doc() function, there are several things we could do. We could specify a particular <po> element:

<xsl:variable name="purchase-orders"

A more practical solution would be to put the doc() function into an <xsl:for-each> element:

<xsl:for-each select="/report/po">
  <xsl:variable name="purchase-orders"

We could also change our input document so that it has only a single ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.