Name
[2.0] doc()
Given a URI, returns a document node representing the contents of that URI.
Syntax
document-node()?doc($uri as xs:string?)
Inputs
A URI. The format of the URI is implementation-defined.
Output
A document node that represents the contents of the requested URI.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.5, “Functions and Operators that Generate Sequences.”
Example
Here is an example that uses Saxon’s support for simple
filenames as URIs. We’ll invoke the doc() function to load this XML
document:
<?xml version="1.0"?>
<!-- polist.xml -->
<collection>
<doc href="po38292.xml"/>
<doc href="po38293.xml"/>
<doc href="po38294.xml"/>
<doc href="po38295.xml"/>
</collection>Here’s our stylesheet:
<?xml version="1.0"?> <!-- doc.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>
A test of the doc() function:</xsl:text> <xsl:text>

 Here are all the purchase orders </xsl:text> <xsl:text>listed in polist.xml:</xsl:text> <xsl:for-each select="doc('polist.xml')/collection/doc"> <xsl:text>
 </xsl:text> <xsl:value-of select="@href"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
We use the doc()
function to load the file polist.xml, and
then we use <xsl:for-each> to process the
contents of the document we just loaded. Here are the
results:
A test of the doc() function: Here are all the purchase orders listed in polist.xml: po38292.xml po38293.xml po38294.xml ...
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