<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.lang.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.lang</api:function-name><api:suggest>fn.lang</api:suggest><api:suggest>fn</api:suggest><api:suggest>lang</api:suggest><api:function-link mode="xquery" fullname="fn:lang">/apidoc/8.0/fn:lang.xml</api:function-link><api:function mode="javascript" name="lang" type="builtin" lib="fn" category="NodeBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.lang"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
This function tests whether the language of $node, or the context node if the
second argument is omitted, as specified by xml:lang attributes is the same
as, or is a sublanguage of, the language specified by $testlang. The
language of the argument node, or the context node if the second argument is
omitted, is determined by the value of the xml:lang attribute on the node,
or, if the node has no such attribute, by the value of the xml:lang
attribute on the nearest ancestor of the node that has an xml:lang
attribute. If there is no such ancestor, then the function returns false
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the second argument is omitted and the context item is undefined an error is
raised: [err:XPDY0002]. If the context item is not a node an error is raised
[err:XPTY0004].
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $testlang is the empty sequence it is interpreted as the zero-length string.
</p><p xmlns="http://www.w3.org/1999/xhtml">
The relevant xml:lang attribute is determined by the value of the XPath
expression:  (ancestor-or-self::* /@xml:lang)[last()]
</p>
<p xmlns="http://www.w3.org/1999/xhtml">If this expression returns an empty sequence, the function returns false.
</p><p xmlns="http://www.w3.org/1999/xhtml">
Otherwise, the function returns true if and only if the string-value of the
relevant xml:lang attribute is equal to $testlang based on a caseless default
match as specified in section 3.13 of [The Unicode Standard], or if the
string-value of the relevant testlang attribute contains a hyphen, "-"
(The character "-" is HYPHEN-MINUS, #x002D) such that the part of the
string-value preceding that hyphen is equal to $testlang, using caseless
matching.
</p>
</api:summary><api:params><api:param name="testlang" type="xs:string?"><api:param-description>
The language against which to test the node.
  </api:param-description><api:param-name>testlang</api:param-name><api:param-type>String?</api:param-type></api:param><api:param name="node" type="node()" optional="true"><api:param-description>
The node to test.
  </api:param-description><api:param-name>node</api:param-name><api:param-type>Node</api:param-type></api:param></api:params><api:return>Boolean</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var item1 = xdmp.unquote('&lt;a xml:lang="en"&gt;&lt;quantity&gt;5.0&lt;/quantity&gt;&lt;/a&gt;')
    .toArray()[0].root;
fn.lang("en", item1);
=&gt; true
</pre></api:example></api:function></api:function-page>