Name
[2.0] encode-for-uri()
Given a string, encodes that string for use in a URI.
Syntax
xs:stringencode-for-uri(
$uri-part as xs:string?
)
Input
A string containing the value to be escaped.
Output
The input string with the appropriate characters escaped as
percent-encoded values. All characters are escaped
except the following: upper- and lowercase
letters A–Z
, the digits
0–9
, the hyphen-minus character
(“–
” or -
), the underscore or low-line
character (“_
” or _
), the period or full stop
(“.
” or E;
), and the tilde (“~
” or ~
). For example, the space
character,  
, is
escaped as %20
. All hexadecimal
digits are in uppercase, so the character á
(á
, a lowercase a
with an acute accent) is escaped as
%E1
.
Keep in mind that the encode-for-uri()
function escapes
every character, so you should use it to escape only the parts of
a URI that need to be escaped. For example, calling encode-for-uri('http://www.oreilly.com/')
returns http%3A%2F%2Fwww.oreilly.com%2F
, which
is almost certainly not what you want.
If the value of the 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
Here’s a stylesheet that features two examples courtesy of the XQuery 1.0 and XPath 2.0 Functions and Operators spec:
<?xml version="1.0" encoding="utf-8"?>
<!-- encode-for-uri.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> ...
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.