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:local-name

Category:

Node names, identifiers and URI information

Origin:

XPath 1.0

Return value:

A xs:string string; the local portion of the QName of a node – in other words, that part of the identifier which follows the colon after the prefix.

Call/Arguments:

fn:local-name($node-sequence?)

$node-sequence:

Optional. The argument of the function is a node sequence which, in general, consists of at least one node. The local identifier of this node or the one of the first node of the node sequence is returned by the function. If the sequence is empty, an empty string is returned. If the argument passed on is not a node or a node sequence, an error is reported.

Purpose of use:

Used on an element node, the local-name() function returns the local part of the element identifier. As a consequence, the return value has to lexically correpond to the xs:NCName type.

Therefore, in case of a <example:test> element passed on, the "test" string is returned, likewise applied to the prefix-less <test> element. Analogously, for attribute nodes the local part of the identifier behind a possible namespace prefix is returned.

If an argument is passed on, but this results in the empty sequence, the function returns the empty string. If, however, no argument at all is returned, the local identifier of the context node is returned per default. However, an error message occurs if no context node exists (err:XPDY0002) or the context item is not a node (err:XPTY0004).

Used on a document node, the function returns the empty string since such a node is nameless per definition. The same applies for the application on text and comment nodes.

The local identifier of a processing instruction corresponds to its target, in other words to the name of the addressed application.

Used on a namespace node, the function returns the prefix string which is representative for the namespace and the empty string in case it is the default namespace.

Example 1 – template for elements with the same local-name:

<xsl:template match="*[fn:local-name()='example']">
<!-- all elements with local name 'example' regardless of their prefixes-->
</xsl:template>

In this example all elements are gathered whose local identifiers correspond to the »example« string, which means without taking into account the prefix portion of their QName. This may be useful in case same-named elements shall be treated identically despite different prefixes but, at the same time, they cannot be distinguished based on the namespace.

Example 2 – processing call for elements with the same local-name:

<xsl:apply-templates select="*[fn:local-name()='example']"/>

Here, the function is called with xsl:apply-templates, analogously to the example above – the function without argument within a predicate test is applied to all tested context nodes.

Function definition:

XPath 1.0:

local-name(node-set?) => string

XPath 2.0:

fn:local-name() as xs:string

fn:local-name($arg as node()?) as xs:string

   

<< 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