Subject: Re: [xsl] i18n and l10n question From: Nicolas Van Cleemput <nicolas.vancleemput@xxxxxxxx> Date: Tue, 07 Nov 2006 10:25:21 +0100 |
I'm still having some problems putting this to use in our case, but I thank you already because I've learned some new ways of doing things from this, (As you might have guessed: these are my first steps in XSL).
I tried to adjust your tip to what we already had, but it didn't seem to work. It gave no errors (after I closed some brackets and typed some extra commas ;)), but it just printed the default text several times.
<factory> <i18n> <properties> <entry key="factory.name">Turan Graph</entry> </properties> <node name="nl"> <properties> <entry key="factory.name">Turan Graaf</entry> </properties> </node> </i18n> </factory>
I made this xslt-file that should transform the TuranGraphFactory.xml file to a html-file:
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="locale"/> <xsl:variable name="locale2" select="substring-before($locale,'_')"/> <xsl:key name="l" match="entry" use="concat(../@name,' ',@key)"/>
<xsl:template match="factory"> <html> <body> <h1> <xsl:variable name="key" select="'factory.name'"/> <xsl:for-each select="//entry"> <xsl:choose> <xsl:when test="key('l',concat($locale,' ',$key))"> <xsl:apply-templates select="key('l',concat($locale,' ',$key))"/> </xsl:when> <xsl:when test="key('l',concat($locale2,' ',$key))"> <xsl:apply-templates select="key('l',concat($locale2,' ',$key))"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="key('l',concat(' ',$key))"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </h1> </body> </html> </xsl:template> </xsl:transform>
The desired result would be a simple html-file that contained one title with the name of the graph in the current locale. However I get a file that contains one title that is the name of the graph four times: first the english, then the dutch, then the english and again the dutch.
if the file you posted is in locale.xml and you have an input element something like <ref key="id1"/> which is supposed to produce this text, then something like
<xsl:stylesheet... <xsl:param name="locale"/> <xsl:variable name="locale2" select="substring-before($locale,'-')"/> <xsl:key name="l" match="entry" use="concat(../@name,' ',@key)"/>
<xsl:template match="ref"> <xsl:variable name="key" select="@key"/> <xsl:for-each select="document('locale.xml')"> <xsl:choose> <xsl:when test="key('l',concat($locale,' '$key)"> <xsl:apply-templates select="key('l',concat($locale,' ',$key)"/> </xsl:when> <xsl:when test="key('l',concat($locale2,' '$key)"> <xsl:apply-templates select="key('l',concat($locale2,' ',$key)"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="key('l',concat(' ',$key)"/> </xsl:otherwise> </xsl:choose>
which (if I typed it in right) would mean that setting the external local parameter to "en-uk" would mean it would try in order, en-uk, en, and the defualt.
David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] i18n and l10n question, David Carlisle | Thread | Re: [xsl] i18n and l10n question, David Carlisle |
RE: [xsl] RE: Help needed to transf, Michael Kay | Date | Re: [xsl] i18n and l10n question, David Carlisle |
Month |