localization techniques and code review

Subject: localization techniques and code review
From: "Haroon Rafique" <haroon@xxxxxxxxxxxx>
Date: Fri, 17 Nov 2000 09:33:36 -0500
A few notes about my request:

1. I'm a beginner and have just started to learn XSL
2. I'm using Cocoon 1.8 for XSLT on Win 2000 professional.
3. Boy is there a lot to learn here....
4. I have looked at the archives and still feel the need to post so humor
me, please

The objectives are:
1. To learn more about XSL
2. To get some advice on how to handle localization issues
3. What is xml:lang and should I have been using that instead?

I looked at the archives and came across a partially broken example, which I
adapted to my needs and I got it work. However, I am interested in finding
out if I should be using a better methodology (since there is more than one
way to do everything in XSL. (Hey! that's just like perl).

I want to iterate over the fields in this file...

<?xml version="1.0"?>
<!-- test.xml -->
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>

and look up their translations in this file...

<?xml version="1.0"?>
<!--  localization.xml -->
    <word name="_FIRST_NAME">
        <translation lang="es">Nombre</translation>
        <translation lang="en">First Name</translation>
        <translation lang="it">Nome</translation>
     <word name="_OCCUPATION">
                <translation lang="es">Ocupacion</translation>
                <translation lang="en">Occupation</translation>
                <translation lang="it">Occupazione</translation>

this is how I did it. The variable selectLang defaults to 'en' but can be
supplied as a URL parameter, thereby giving the translation in another
language (no error checking is being done, if the translation doesn't

<?xml version="1.0"?>
<!-- test.xsl -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  <!-- set default language to 'en' if not supplied from URL paramter -->
  <xsl:param name="selectLang" select="'en'" />
  <xsl:variable name="trans" select="document('localization.xml')" />
    <!-- set a key called translate     -->
    <!-- which indexes the name property of ancestor word's -->
    <!-- concatenated with a hyphen and the lang property -->
    <!-- of all translation nodes    -->
    <xsl:key name="translate" match="translation"
use="concat(ancestor::word/@name,'-',@lang)" />
    <xsl:template match="page">
        <xsl:value-of select="$selectLang" />
        <hr />
        <xsl:for-each select="//field">
          <xsl:param name="field" select="." />
          <xsl:value-of select="$field" />
            <xsl:for-each select="document('localization.xml')">
select="key('translate',concat($field,'-',$selectLang))" />

Expected output (with URL test.xml):

Expected output (with URL test.xml?selectLang=es)

1. Am I on the right track? What about the use of nested
<xsl:for-each select="document('localization.xml')">
2. What if I need to re-print the table again? Could I have somehow stored
the results of the document() call to be able to reuse it at a later stage?

Thanks for your help,
Haroon Rafique

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread