O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

[2.0] base-uri()

Returns the base URI of a given node.

Syntax

xs:anyURI? base-uri(node()?)
xs:anyURI? base-uri()

Input

A node. Without an argument, base-uri() returns the base URI of the context item.

Output

The base URI of the given node.

The base-uri() function works with the XML Base specification. By default the base URI is the URI of the XML document itself, but a document can change that by using the xml:base attribute on any element.

If a given node does not have a base URI property and the node has a parent, base-uri() looks at the node’s ancestors. The function attempts to find the base URI of the node’s parent, then its parent’s parent, and so forth, until it either finds a base URI property or reaches a node that does not have a parent. If no base URI property can be found, base-uri() returns the empty sequence. If the argument to base-uri() is the empty sequence, the function returns the empty sequence.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 2, “Accessors.”

Example

Here’s a revised version of our list of cars. Notice that the <manufacturer> elements all use the xml:base attribute to define a new base URI:

<?xml version="1.0" encoding="utf-8"?>
<!-- xmlbase.xml -->
<cars>
  <manufacturer name="Chevrolet"
    xml:base="http://www.chevrolet.com/">
    <car>Cavalier</car>
    <car>Corvette</car>
    <car>Impala</car>
    <car>Malibu</car>
  </manufacturer>
  <manufacturer name="Ford"
    xml:base="http://www.ford.com/"> <car>Pinto</car> <car>Mustang</car> <car>Taurus</car> </manufacturer> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required