XSLT and XPath function reference in alphabetical order

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

fn:resolve-uri

Category:

Association and localisation of nodes and resources at runtime

Origin:

XPath 2.0

Return value:

A xs:anyURI URI in the form of an absolute URI.

Call/Arguments:

fn:resolve-uri($resolveURI, $baseURI?)

$resolveURI:

Obligatory. A xs:string string in the lexical form of a relative or an absolute URI string. The empty string as input value is permitted.

$baseURI:

Optional. A xs:string string against which the URI string of the first argument shall be resolved. Lexically, the argument has to correspond to an absolute URI of xs:anyURI type.

Purpose of use:

The fn:resolve-uri() function is used in order to resolve any relative input URI against a base URI and to construct in such a way an absolute URI of xs:anyURI type.

For this purpose, a base URI passed on as second argument can be used as reference element. This base URI must have the form of an absolute URI, otherwise the error message »Invalid argument to fn:resolve-uri()« (err:FORG0002) occurs.

If you do not want to pass on the second argument, the base URI of the static context of the function call is used as reference point. If in the static context no base URI is defined, the error »Base-uri not defined in the static context« (err:FONS0005) is reported.

If the first argument is the empty string (a lexically correct URI string), the function returns the base URI passed on or the URI of the static context. In principle, one can say that a relative URI consisting of the empty string is resolved against the base URI.

If the first argument does not lexically correspond to a xs:anyURI, also the error »Invalid argument to fn:resolve-uri()« (err:FORG0002) occurs. If, however, the empty sequence is passed on as first argument, the function returns an empty result sequence.

If the URI to be resolved is already an absolute URI, it is returned unchanged. In this case, it plays no role whether a second argument was passed on with a base URI or not. Therefore, an absolute URI as first function argument is definitively permitted (the indication $relative in the function signature is misleading).

Example 1 – construction of an absolute URI with base URI:

fn:resolve-URI( 'example/test',

'http://www.example.de/'

)

resolves the relative URI against the base URI passed on and returns the following absolute URI:

www.example.de

example/test

Example 2 – passing on the empty string:

fn:resolve-URI( '',

'http://www.example.de/'

)

resolves the empty string against the base URI passed on and returns the following absolute URI:

www.example.de

Example 3 – construction of an absolute URI, static base URI:

fn:resolve-URI('example/test')

resolves the relative URI against the base URI of the static context and returns it (environment dependently) as absolute URI:

file:/D:/xslt2/xpath2-functions/example/test

Example 4 – passing on the empty string, static base URI:

fn:resolve-URI('')

resolves the empty string against the base URI of the static context and returns it (environment dependently) as absolute URI:

file:/D:/xslt2/xpath2-functions/

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:resolve-uri($relative as xs:string?) as xs:anyURI?

fn:resolve-uri($relative as xs:string?,

$base as xs:string) as xs:anyURI?

   

<< back next >>

 

 

 


Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.


Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany