URI Functions

resolve-uri($relative, $base) joins a reference to a base by RFC 3986 rules, and base-uri() and document-uri() say where a node came from. encode-for-uri() escapes all but unreserved characters (for one path segment or query value); iri-to-uri() and escape-html-uri() encode only the non-ASCII characters of an address. QName(), resolve-QName(), prefix-from-QName() and in-scope-prefixes() handle qualified names.

Building cover-image URLs
xp 'encode-for-uri(//book[5]/title)' \
   'resolve-uri("../covers/b5.jpg", "https://cdn.example.com/bn/v2/")'
Output
encode-for-uri(//book[5]/title)        => "The%20Clockmaker%27s%20Paradox"
resolve-uri("../covers/b5.jpg", "https://cdn.example.com/bn/v2/") =>
  "https://cdn.example.com/bn/covers/b5.jpg"

Escape each piece you splice into an address, then let resolve-uri() attach it instead of concatenating strings.


URI Functions

URI functions resolve, encode, and inspect URIs and QNames. The resolve-QName(), namespace-uri-for-prefix(), and in-scope-prefixes() examples below assume the same <menu> document (with the ns namespace prefix) used in Node Functions.
resolve-uri("AB/C","http://D")http://D/AB/C
encode-for-uri("http://A B")http%3A%2F%2FA%20B
iri-to-uri("http://www.example.com/~bébé")http://www.example.com/~b%C3%A9b%C3%A9
resolve-QName("ns",menu)ns
QName("http://example.com","hello")hello
prefix-from-QName(QName("http://example.com","hello"))()
local-name-from-QName(QName("http://example.com","hello"))hello
namespace-uri-from-QName(QName("http://example.com","hello"))http://example.com
namespace-uri-for-prefix("ns",menu)http://example.com
in-scope-prefixes(menu)(xml, ns)
ch03-uri-functions.xpath.txt
merged-01-01-ch03-uri-functions.xpath.txt
resolve-uri("AB/C", "http://D")
Output
http://D/AB/C