base-uri() ➔ xs:anyURI?

Returns the base URI of the context node.

There are no arguments



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

Returns the base URI of a specified node.





The node whose base URI is required





Links to W3C specifications

XPath 3.1 Functions and Operators


If a node is supplied to Saxon as a JAXP Source object, then the base URI of the document node will be the value returned by the method Source.getSystemId(). The base URI of other nodes within the document may differ from this for either of two reasons:

It is possible for the base URI of a document to be absent (unknown). This happens when the document is supplied to Saxon with no location information: for example when the node is represented using a tree model such as DOM that has no base URI information; or when a Source is supplied for which getSystemId() returns null. The most common example of this is a Source created using new StreamSource(new FileInputStream("input.xml")). The problem can be fixed by using the second argument of the StreamSource constructor, or by using the constructor that expects a File rather than an InputStream.

If the base URI is absent, the base-uri() function returns an empty sequence. No error occurs unless an operation is needed that requires a base URI, for example using the base URI as an argument of resolve-uri().