XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
Node names, identifiers and URI information
XSLT 1.0, XPath 2.0 Core
A Boolean value true or false, depending on whether a xml:lang attribute is valid for the context node examined with a value corresponding to the language code identifier passed on.
Obligatory. The argument has to be a xs:string string which corresponds to an abbreviation for a language code in terms of the content. This may be one of the defined codes according to ISO 639, a langauge code registered at the IANA (Internet Assigned Numbers Association) or a user-defined language code. The empty string is permitted as value.
(new in XPath 2.0)
Optional. A XPath expression which indicates a node unless the function shall be applied to the context node. This argument is not available in XPath 1.0. If the argument is passed on, it must not be the empty sequence.
Purpose of use:
The xml:lang attribute indicates the languge of the content of an element or of the content of its descendants unless they do have an own, different xml:lang attribute.
The fn:lang() function compares the string passed on to it with the value of the xml:lang attribute of the context node or – provided that a second argument has been passed on – with the xml:lang attribute of the node indicated in this way. If no appropriate attribute can be found there, the function searches, starting from this node in the direction of the ancestor axis, for the first element appearing there containing such an attribute.
The comparison is not case-sensitive, why the notation of the language identifier passed on does not play a role (caseless matching). If the default value matches with the attribute value, which means the language of the element content corresponds to the queried language, the function returns the Boolean value true, otherwise false.
For this purpose, only the main group of the langauge indication is compared. Suffixes of the language identifier beginning with a hyphen in xml:lang (#x002D) which specify subgroups of a language are ignored: Therefore, the function returns equally true for all subgroups of the queried language. For example, also a xml:lang attribute with the value "fr-CA" for Canadian French results in true when testing for "fr" since the -CA character string within the langauge identifier is rejected during the comparison.
If the empty string is passed on to the function as language identifier, the function returns the value false (the empty string is interpreted as »not a language«).
If neither for the context node (or the alternatively indicated node) nor for one of its descendants a valid xml:lang attribute can be found, the function returns the value false.
However, an error message occurs if no second argument has been passed on and simultaneously no context node exists (err:XPDY0002) or the context item is not a node (err:XPTY0004).
Possible compatibility problems:
If in XPath 2.0 the input sequence consists of more than one item, an error is reported; also if the value passed on is a non-typed node. Otherwise the typed value is used as a basis for the test. There are no typed nodes in XSLT 1.0. Here, in the case of a node set passed on, its first node is processed.
Example - query of a language code:
If the functions is used in the following way:
the value true is returned for the <para> container as context node in all of the following cases except for the last one:
<!-- this is French --> <para xml:lang="fr"/> <!-- this is French --> <div xml:lang="fr"> <!-- the para container "inherits" the language indication --> <para/> </div> <!-- this is French --> <para xml:lang="FR"/> <!-- this is Canadian French --> <para xml:lang="fr-CA"/> <!-- this is Japanese --> <para xml:lang="jp"/>
lang(string) => boolean
fn:lang($testLang as xs:string?) as xs:boolean
fn:lang($testLang as xs:string?,
$node as node()) as xs:boolean
|<< 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