<html>
<head>
<title>lang() Function</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">lang() Function</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
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 <span class="LITERAL">xml:lang</span> attribute.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Inputs</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>A string representing a language code. If the context node has a language of <span class="LITERAL">xml:lang="en-us"</span>, invoking the <span class="LITERAL">lang()</span> function with any of the values <span class="LITERAL">en</span>, <span class="LITERAL">EN</span>, and <span class="LITERAL">en-us</span> returns the boolean value <span class="LITERAL">true</span>, while invoking <span class="LITERAL">lang()</span> with the value <span class="LITERAL">en-gb</span> returns the boolean value <span class="LITERAL">false</span>.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Output</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>If the argument string is the same as, or is a sublanguage of, the context node's language, <span class="LITERAL">lang()</span> returns the boolean value <span class="LITERAL">true</span>. If the context node does not have an <span class="LITERAL">xml:lang</span> attribute, then the value of the <span class="LITERAL">xml:lang</span> attribute of its nearest ancestor is used instead. If there is no such attribute, then the <span class="LITERAL">lang()</span> function returns the boolean value <span class="LITERAL">false</span>. When comparing the language code of the context node with the argument string, the <span class="LITERAL">lang()</span> function ignores case.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XPath section 4.3, Boolean Functions.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Here is an XML document that uses language codes:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list xml:lang="en"&gt;
  &lt;title&gt;Albums I've bought recently:&lt;/title&gt;
  &lt;listitem&gt;The Sacred Art of Dub&lt;/listitem&gt;
  &lt;listitem&gt;Only the Poor Man Feel It&lt;/listitem&gt;
  &lt;listitem&gt;Excitable Boy&lt;/listitem&gt;
  &lt;listitem xml:lang="sw"&gt;Aki Special&lt;/listitem&gt;
  &lt;listitem xml:lang="en-gb"&gt;Combat Rock&lt;/listitem&gt;
  &lt;listitem xml:lang="zu"&gt;Talking Timbuktu&lt;/listitem&gt;
  &lt;listitem xml:lang="jz"&gt;The Birth of the Cool&lt;/listitem&gt;
&lt;/list&gt;</pre></span>
<p>Here's a stylesheet that uses the <span class="LITERAL">lang()</span> function:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text"/&gt;

<!--<?troff .Nd 10?>-->
  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:for-each select="list/listitem"&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="lang('EN')"&gt;
          &lt;xsl:text&gt;Here's an English-language album: &lt;/xsl:text&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:text&gt;-------&gt; Here's some World music: &lt;/xsl:text&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
      &lt;xsl:value-of select="."/&gt;
      &lt;xsl:value-of select="$newline"/&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Finally, here are the results:</p>
<span class="PROGRAMLISTING"><pre>

Here's an English-language album: The Sacred Art of Dub
Here's an English-language album: Only the Poor Man Feel It
Here's an English-language album: Excitable Boy
-------&gt; Here's some World music: Aki Special
Here's an English-language album: Combat Rock
-------&gt; Here's some World music: Talking Timbuktu
-------&gt; Here's some World music: The Birth of the Cool
</pre></span>
</td>
</tr>
</table>
</div>
</body>
</html>