Name

[2.0] iri-to-uri()

Given a string containing an Internationalized Resource Identifier (IRI), this function converts it to a URI. URI syntax allows only a subset of roughly 60 ASCII characters, which is inadequate for most of the world’s languages. IRI syntax addresses this problem; this function translates IRI syntax to URI syntax.

Syntax

xs:string iri-to-uri(xs:string?)

Inputs

An xs:string containing an IRI.

Outputs

An xs:string with the appropriate characters escaped so that they are legal for a URI. (If you want all the details, see RFC 3987, Internationalized Resource Identifiers [IRIs], available at http://www.ietf.org/rfc/rfc3987.txt. For the details of URI syntax, see RFC 3986, Uniform Resource Identifiers [URI]: Generic Syntax, available at http://www.ietf.org/rfc/rfc3986.txt.)

This function does not escape the percent character (%). If you want to use this function, you must escape all the percent signs yourself (calling replace-string($string, '%', '%25') will do the trick) before you call iri-to-uri().

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 are two examples from the spec:

<?xml version="1.0" encoding="utf-8"?>
<!-- iri-to-uri.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>&#xA;Tests of the iri-to-uri() function:</xsl: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.