>> English << | Français | Deutsch | Magyar | 中文 | Polski ZVON > Tutorials > XSLT Tutorial
>> Page 46 << | Prev | Next | Contents | Element Index

The lang function returns true or false depending on whether the language of the context node as specified by xml:lang attributes is the same as or is a sublanguage of the language specified by the argument string. The language of the context node is determined by the value of the xml:lang attribute on the context node, or, if the context node has no xml:lang attribute, by the value of the xml:lang attribute on the nearest ancestor of the context node that has an xml:lang attribute. If there is no such attribute, then lang returns false. If there is such an attribute, then lang returns true if the attribute value is equal to the argument ignoring case, or if there is some suffix starting with - such that the attribute value is equal to the argument ignoring that suffix of the attribute value and ignoring case.

XSLT stylesheet 1

XML Source
<source>

<P xml:lang="de">
     <text xml:lang="cs">a</text>
     <text xml:lang="en">and</text>
     <text>und</text>
</P>

</source>

Output
<P>Czech: a</P>

<P>English: and</P>

<P>German: und</P>

HTML view

Czech: a

English: and

German: und

XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="text">
     <P>
          <xsl:choose>
               <xsl:when test='lang("cs")'>
                    <xsl:text>Czech: </xsl:text>
               </xsl:when>
               <xsl:when test='lang("en")'>
                    <xsl:text>English: </xsl:text>
               </xsl:when>
               <xsl:when test='lang("de")'>
                    <xsl:text>German: </xsl:text>
               </xsl:when>
          </xsl:choose>
          <xsl:value-of select="."/>
     </P>
</xsl:template>


</xsl:stylesheet>