Name
[2.0] escape-html-uri()
Given an HTML URI, returns that URI with its non-ASCII characters escaped as UTF-8 characters.
Syntax
xs:stringescape-html-uri(xs:string?)
Inputs
An xs:string representing
an HTML URI.
Output
The input string with all characters outside the range
  to ~ escaped as UTF-8 characters.
When a character is converted to UTF-8, it is represented as
octets in the form %HH, where
HH is the hexadecimal
representation of the octet. The hexadecimal characters generated
by escape-html-uri() are in
uppercase. This function conforms to the rules for escaping
non-ASCII characters defined in the HTML 4.0 spec.
If argument is the empty sequence, a zero-length string is returned.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 7.4, “Functions on String Values.”
Example
This stylesheet uses escape-html-uri() to correctly
encode characters in the URI (in this case é, a lowercase e with an acute accent)
as UTF-8. (This example was taken from the XQuery 1.0 and XPath
2.0 Functions and Operators spec.)
<?xml version="1.0" encoding="UTF-8"?> <!-- escape-html-uri.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>
Tests of the escape-html-uri() function:</xsl:text> <xsl:text>

 escape-html-uri</xsl:text> <xsl:text>('http://www.example.com/~bébé') = 
 </xsl:text> <xsl:value-of select="escape-html-uri('http://www.example.com/~bébé')"/> </xsl:template> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access