Use the standard XPath / XQuery functiondoc-available() .
From Spec:
fn:doc-available($uri as xs:string?) as xs:boolean
Summary : a function returns true if and only if the function call fn:doc($uri)returns a node document.
If $uriis an empty sequence, this function returns false.
If the call fn:doc($uri)returns a node document, this function returns true.
If $uriit is not a valid URI in accordance with the rules applicable during implementation fn:doc, an error occurs [err: FODC0005].
Otherwise, this function returns false.
true, fn:doc($uri) node. fn:doc , .