Name
lang()
Determines whether a given language string is the
same as, or is a sublanguage of, the language of the context node,
as defined by an xml:lang
attribute.
Syntax
[1.0] booleanlang(string)[2.0] xs:booleanlang(xs:string?)[2.0] xs:booleanlang(xs:string?,node())
Inputs
A string representing a language code. If the context node
has a language of xml:lang="en-us", invoking the lang() function with any of the
values en, EN, and en-us returns the boolean value
true, while invoking lang() with the value en-gb returns the boolean value false.
Output
If the argument string is the same as, or is a sublanguage
of, the context node’s language, lang() returns the boolean value
true. If the context node does
not have an xml:lang attribute,
then the value of the xml:lang
attribute of its nearest ancestor is used instead. If there is no
such attribute, then the lang() function returns the boolean
value false. When comparing the
language code of the context node with the argument string, the
lang() function ignores
case.
Defined in
[1.0] XPath section 4.3, “Boolean Functions.”
[2.0] XQuery 1.0 and XPath 2.0 Functions and Operators section 14, “Functions and Operators on Nodes.”
Example
Here is an XML document that uses language codes:
<?xml version="1.0"?> <!-- albums.xml --> <list xml:lang="en"> <title>Albums I've bought recently:</title> <listitem>The Sacred Art of Dub</listitem> <listitem>Only the Poor Man Feel It</listitem> <listitem>Excitable Boy</listitem> <listitem xml:lang="sw">Aki Special</listitem> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access