fn:document-uri

Returns the URI of a document.

document-uri() ➔ xs:anyURI?

There are no arguments

Result

xs:anyURI?

document-uri($arg as node()?) ➔ xs:anyURI?

Arguments

 

$arg

node()?

The node whose document URI is required

Result

xs:anyURI?

Namespace

http://www.w3.org/2005/xpath-functions

Links to W3C specifications

XPath 3.1 Functions and Operators

Saxon availability

Available in all Saxon editions.

Details

The W3C specification requires that if document-uri(D) = U, then doc(U) is D. A consequence of this rule is that two different documents cannot have the same document URI. This realisation led to a significant change in the implementation of the function beween Saxon 10 and 11, with the effect that many documents no longer have a document URI. For example, at one time a document built from a JAXP Source object would automatically have a document-uri() based on the systemID property of the Source. This is no longer the case, because there is no way of preventing two different Source objects having the same systemID property.

For documents read using the XPath doc() or document() functions, or the XSLT <xsl:source-document> instruction, it will normally be the absolutized URI that was used to read the document, even if a user-supplied URIResolver redirected the request to some other URI. By contrast, the base-uri() function returns the URI of the actual document returned by the URIResolver.

Internally, Saxon maintains a document pool whose scope is a particular transformation (or query). The document pool is a set of (URI, document) pairs, and a document has a document-uri() property if and only if there is an entry for this pair in the document pool.

Documents read using the collection() function are added to the document pool (and therefore have a document-uri() property) if and only if the collection is stable. In Saxon, for performance reasons, collections are not stable unless the configuration option STABLE_COLLECTION_URI is set, or unless stability is requested in some other way, for example by including the parameter stable=yes in the collection URI.