[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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)
xslt parameter internationalization
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:choose>
    <xsl:when test="$string-name='next page'">
      <xsl:choose>
        <xsl:when test="lang()='de'">naechste Seite</xsl:when>
	<xsl:otherwise>next page</xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:when test="$string-name='Results of database query'">
      <xsl:choose>
        <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"
	                select="translate(ancestor-or-self::*/@xml:lang,
			                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
			                  'abcdefghijklmnopqrstuvwxyz')"/>
	  <xsl:choose>
	    <xsl:when test="$lang='zh-tw'">Traditional Chinese text</xsl:when>
	    <xsl:when test="$lang='zh-cn'">Simplified Chinese text</xsl:when>
	  </xsl:choose>
	</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>
      </xsl:choose>
    </xsl:when>
  </xsl:choose>
</xsl:template>

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

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

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.

Regards,


Tony Graham
======================================================================
Tony Graham                            mailto:tgraham@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
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:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.