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:string escape-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>&#xA;Tests of the escape-html-uri() function:</xsl:text>

    <xsl:text>&#xA;&#xA;  escape-html-uri</xsl:text>
    <xsl:text>('http://www.example.com/~bébé') = &#xA;    </xsl:text>
    <xsl:value-of
      select="escape-html-uri('http://www.example.com/~bébé')"/> </xsl:template> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.