logolineright
bottomhttp://xml.apache.org/http://www.apache.org/http://www.w3.org/
join
Overview
separator
Compiler design
separator
Whitespace
xsl:sort
Keys
Comment design
separator
lang()
Unparsed entities
separator
If design
Choose|When|Otherwise design
Include|Import design
Variable|Param design
separator
Runtime
separator
Internal DOM
Namespaces
separator
Translet & TrAX
XPath Predicates
Xsltc Iterators
Xsltc Native API
Xsltc TrAX API
Performance Hints
close
Functionality
 

The xml:lang can be used to determine the language for a node or a node-set. The attribute can be used to store language-specific data in an XML document:

    <phrases>
      <greeting xml:lang="en">Hello!</greeting>
      <greeting xml:lang="no">Hei!</greeting>
      <greeting xml:lang="fr">Salut!</greeting>
      <greeting xml:lang="es">Hola!</greeting>
      <greeting xml:lang="de">Sweinhund!</greeting>
    </phrases>
  

The XSL stylesheet can use the lang() function to select the element with the desired language:

    <xsl:template match="greeting">
      <xsl:if test="lang("de")>
        <xsl:value-of select="."/>
        <xsl:text> Grossglucklicher wunche!</xsl:text>
      </xsl:if>
    </xsl:template>
  

Implementation
 

The DOM interface has been given a method that returns the language for a given node. The language is returned as a string (on whatever format is used in the XML document - should be iso), and may be null if no language is defined.

    public String DOM.getLanguage(int node);
  

The BasisLibrary class has a static method that will compare the language of the context node with some other language and return the result as a boolean.

    public static boolean BasisLibrary.testLanguage(String language, DOM dom, int node);
  

The compiled code for the lang() method calls this method in the BasisLibrary and leaves the result on the stack for the calling element.



dot
Copyright © 2004 The Apache Software Foundation. All Rights Reserved.