fn:escape-html-uri
Escapes a URI in the same way that HTML user agents handle attribute values expected to contain URIs.
Signature
fn:escape-html-uri($uri as xs:string?) as xs:string
Properties
This function is deterministic, context-independent, and focus-independent.
Rules
If $uri
is the empty sequence, the function returns the zero-length
string.
Otherwise, the function escapes all characters except
printable characters of the US-ASCII coded character set, specifically the codepoints between 32 and 126 (decimal) inclusive. Each
character in $uri
to be escaped is replaced by an escape sequence, which is
formed by encoding the character as a sequence of octets in UTF-8, and then representing
each of these octets in the form %HH, where HH is the hexadecimal representation of
the
octet. This function must always generate hexadecimal values using the upper-case
letters A-F.
Notes
The behavior of this function corresponds to the recommended handling of non-ASCII characters in URI attribute values as described in [HTML 4.0] Appendix B.2.1.
Examples
The expression fn:escape-html-uri("http://www.example.com/00/Weather/CA/Los Angeles#ocean")
returns "http://www.example.com/00/Weather/CA/Los Angeles#ocean"
.
The expression fn:escape-html-uri("javascript:if (navigator.browserLanguage == 'fr') window.open('http://www.example.com/~bébé');")
returns "javascript:if (navigator.browserLanguage == 'fr') window.open('http://www.example.com/~b%C3%A9b%C3%A9');"
.