Re: internationalization / localization of XSLT output

Subject: Re: internationalization / localization of XSLT output
From: Tony Graham <tgraham@xxxxxxxxxxxxxxxx>
Date: Fri, 25 Aug 2000 18:25:10 -0400 (EST)
At 24 Aug 2000 12:03 -0600, Mike Brown wrote:
 > XML has a facility for communicating language-specific information in a
 > standard way: the xml:lang attribute, which you can put on any element,
 > and it will apply to that element and all its descendants, until
 > redeclared, just like namespaces.
 > XSLT/XPath have a function for accessing the language that is in effect
 > for a given element, whether it is declared on that element on or one of
 > its ancestors: lang().

If you do use xml:lang, then you can also do:

<xsl:template name="gettext">
  <xsl:param name="string-name"/>

    <xsl:when test="$string-name='next page'">
        <xsl:when test="lang()='de'">naechste Seite</xsl:when>
	<xsl:otherwise>next page</xsl:otherwise>
    <xsl:when test="$string-name='Results of database query'">
        <xsl:when test="lang()='de'">Ergebnis der Datenbankabfrage</xsl:when>
	<!-- Sometimes you do need to select based on subfields -->
	<xsl:when test="lang()='zh'">
	  <xsl:variable name="lang"
	    <xsl:when test="$lang='zh-tw'">Traditional Chinese text</xsl:when>
	    <xsl:when test="$lang='zh-cn'">Simplified Chinese text</xsl:when>
	<!-- You can use the default string as the parameter and
	     output it as the default when no other language matched -->
	<xsl:otherwise><xsl:value-of select="$string-name"/></xsl:otherwise>

>From your template, all you need is an xsl:call-template with the
right parameter value:

<xsl:template match="/">
      <h1><xsl:call-template name="gettext">
            <xsl:with-param name="string-name"
	                    select="'Results of database query'"/>

You could also do similar stuff when the language is a parameter to
the stylesheet.

Actually, you could use a second stylesheet to generate the named
template above from the sample data shown in other messages in this
thread.  Generating the "zh-tw" and "zh-cn" cases would be tricky if
you are using xml:lang, but those cases wouldn't need the interior
xsl:choose if the language identifier is a parameter to the
stylesheet, since a simple comparison to the language identifier
variable would be sufficient.


Tony Graham
Tony Graham                            mailto:tgraham@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9632
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

 XSL-List info and archive:

Current Thread