Subject: Re: [xsl] xslt and i18n From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 16 Feb 2009 12:20:16 -0500 |
Regarding localisation support in xslt, I've always thought we could take advantage of dynamic despatch, import precedence or template priorities etc
Here's a simple example:
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="f" exclude-result-prefixes="xs f">
<xsl:param name="locale" select="'en_GB'"/>
<xsl:variable name="lang" select="tokenize($locale, '_')[1]"/> <xsl:variable name="country" select="tokenize($locale, '_')[2]"/>
<xsl:function name="f:getLocalisation" as="xs:string"> <xsl:param name="key" as="xs:string"/>
<xsl:variable name="lookup"> <xsl:element name="{$country}"> <xsl:element name="{$lang}"> <xsl:element name="{$key}"/> </xsl:element> </xsl:element> </xsl:variable>
<xsl:apply-templates select="$lookup/*/*"/> </xsl:function>
<xsl:template match="/"> <xsl:value-of select="f:getLocalisation('page.title')"/> </xsl:template>
<xsl:template match="page.title">Default Title</xsl:template> <xsl:template match="en/page.title">General English page title</xsl:template> <xsl:template match="US/en/page.title">Specific US English page title</xsl:template>
</xsl:stylesheet>
The key ("page.title" here) and the locale is passed in as a parameter. The localised values are stored as templates. The key and locale are converted into elements, and then the apply-templates call is made on that temporary tree... and then the rest is taken care of.
http://www.CraneSoftwrights.com/resources/ublss/#ubl2-ss Bosnian, Czech, Danish, Dutch, English, Finnish, French, German, Icelandic, Italian, Norwegian, Portuguese, Slovak and Spanish
Any ideas on how to improve this?
-- Upcoming hands-on XQuery, XSLT, UBL & code list training classes: Brussels, BE 2009-03; Prague, CZ 2009-03, http://www.xmlprague.cz Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xslt and i18n, Andrew Welch | Thread | Re: [xsl] xslt and i18n, Andrew Welch |
Re: [xsl] xslt and i18n, Andrew Welch | Date | Re: [xsl] xslt and i18n, Andrew Welch |
Month |