home contribute faq download

FunctX XQuery Functions

functx:open-ref-document

Resolves a relative URI and references it, returning an XML document

Google
Webxqueryfunctions.com

Description

The functx:open-ref-document function takes the value of $refNode, which is a relative URI reference, resolves it to the base URI to form an absolute URI, then calls the fn:doc function to retrieve the document at that URI.

It uses the base URI of the node itself if available (usually the URI the document was retrieved from). If the node doesn't have a base URI, the base URI of the static context is used (which is defined in the prolog or outside the scope of the query by the processor.

Arguments and Return Type

NameTypeDescription
$refNode node() a node whose value is a relative URI reference
return value document-node()?

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:open-ref-document
  ( $refNode as node() )  as document-node() {

   if (base-uri($refNode))
   then doc(resolve-uri($refNode, base-uri($refNode)))
   else doc(resolve-uri($refNode))
 } ;

Examples

let $in-xml :=
<a href="temp/other.html">Some other file</a>
return
XQuery ExampleResultsExplanation
functx:open-ref-document(
  $in-xml/@href)
The document node of the document at the relative URI temp/other.html. If the base URI of the $in-xml node is http://datypic.com, it would return http://datypic.com/temp/other.html, assuming it's well-formed XML.

See Also

fn:docOpens a document based on a URI

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery