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



Node names, identifiers and URI information


XPath 1.0

Return value:

The function outputs the URI string of the namespace portion of the expanded name of the examined node as xs:anyURI, which means the URI string which is bound to the prefix of the QName.




Always the first node of a sequence of nodes passed on is examined whose namespace URI is outputted as xs:anyURI. If the sequence passed on is empty, the function returns a value of xs:anyURI type which corresponds to the empty string. If no argument is passed on, the function refers to the context node.

Purpose of use:

The function outputs the namespace URI of the first node of a node sequence passed on or of the context node. The xs:anyURI return string is always empty for all node types except for element and attribute nodes with namespace prefix or (non-empty) default namespace.

Without any argument passed on, the function is applied to the context node and returns its namespace URI. However, an error message occurs if no context node exists (err:XPDY0002) or the context item is not a node (err:XPTY0004).

If the expanded name of the regarded node corresponds to its local name (which means the QName has no namespace prefix) and it is in the null namespace (default namespace with empty namespace URI string), the function also returns an empty string.

Also for elements and attributes which are in the null namespace, the empty string is returned. For this purpose, a default namespace with empty URI string must be declared.

Also empty is the return string for elements and attributes which are not in a namespace, which, however, does technically speaking not correspond to the null namespace (in this case, there is no declaration for the default namespace). Nevertheless, this is implemented by XPath in the form of an empty namespace URI string, since there is no null value as data type which may express this circumstance.

Example – output of a namespace URI:

Source document:

<?xml version="1.0"?>
<example xmlns:test="http://www.my-test-namespace.de">
      element without namespace
      element with namespace

Within the <example> element the namespace "http://www.my-test-namespace.de" applies. The second element is bound to this namespace by its test prefix, the first not.


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="example">
   <xsl:for-each select="*">
   <xsl:value-of select="fn:position()"/>. element:
   The name of the element is "
      <xsl:value-of select="fn:name()"/>
   The local name of the element is "
      </xsl:text><xsl:value-of select="fn:local-name()"/>
   The namespace URI is "
      <xsl:value-of select="fn:namespace-uri()"/>

By means of the fn:namespace-uri() function in the stylesheet, the the value of the URI string of the namespace nodes of the processed elements is read out.


<?xml version="1.0" encoding="UTF-8"?>
   1. element:
   The name of the element is "my_element".
   The local name of the element is "my_element".
   The namespace URI is "".

   2. element:
   The name of the elements is "test:my_element".
   The local name of the element is "my_element".
   The namespace URI is "http://www.my-test-namespace.de".

The first processed element is not in a namespace, therefore in this case a xs:anyURI is outputted which corresponds to the empty string. The second element is in the test namespace. Here, the accordingly declared namespace URI is outputted as xs:anyURI. (The quotation marks are generated in the stylesheet.)

Function definition:

XPath 1.0:

namespace-uri(node-set?) => string

XPath 2.0:

fn:namespace-uri() as xs:anyURI

fn:namespace-uri($arg as node()?) 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