Name
[2.0] doc-available()
Tests to see if a given document node is available.
Syntax
xs:booleandoc-available(
$uri as xs:string
)
Inputs
The URI of a document.
Output
This function returns true
if the doc()
function can successfully load
the requested URI. If the argument cannot be converted to an
xs:anyURI
, the XSLT processor
raises an error. Otherwise, doc-available()
returns false
. The format of the URI is
implementation-defined.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.5, “Functions and Operators that Generate Sequences.”
Example
Here’s a short stylesheet that tests whether two documents are available. This uses Saxon’s support for simple filenames as URIs:
<?xml version="1.0"?> <!-- doc-available.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>
Tests of the doc-available() function:
</xsl:text> <xsl:text>
 doc-available('polist.xml') = </xsl:text> <xsl:value-of select="doc-available('polist.xml')"/> <xsl:text>

 doc-available('polist2.xml') = </xsl:text> <xsl:value-of select="doc-available('polist2.xml')"/> </xsl:template> </xsl:stylesheet>
Here are the results:
Tests of the doc-available() function: doc-available('polist.xml') = true doc-available('polist2.xml') = false
The file polist.xml exists in the current directory and can be loaded by Saxon; the file polist2.xml does not exist in the current directory.
Many of the details of the ...
Get XSLT, 2nd Edition 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.