[xsl] Language-specific output

Subject: [xsl] Language-specific output
From: "cavecatem@xxxxxxxxxxxxx" <cavecatem@xxxxxxxxxxxxx>
Date: Wed, 01 Feb 2006 15:31:43
Hi all,

I'm working on a stylesheet that transforms XMP-data to a nicely layouted HTML
I'm working with oxygen and saxon8b (i.e. XSLT 2.0).
Unfortunately, there is the problem of internationalisation, i.e. we have to
be able to create at least a German an English version of the HTML file.

I'm still new to practicing my XML/XSLT-skills so my problems might simply
arise from lack of practice. I didn't find an answer when looking in the list
archive, though.

Rather than maintain two language versions of the stylesheet, I thought I
could try variables in an external file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    <xsl:variable name="TFilename">
        <a lang="de">Datei: </a>
        <a lang="en">File: </a>
    <xsl:variable name="TTitle">
        <a lang="de">XMP Steckbrief der Datei </a>
        <a lang="en">XMP Abstract for the file </a>
    <xsl:variable name="TExifTitle">
        <a lang="de">EXIF-Daten</a>
        <a lang="en">EXIF-Data</a>
    <xsl:variable name="TExposureTime">
        <a lang="de">Belichtungszeit [s]</a>
        <a lang="en">Exposure time [s]</a>

      <xsl:variable name="lightsource">
      <a code="1">
      	<a lang="de">unbekannt</a>
     	 <a lang="en">unknown>/a>
    <a code="1">
    	<a lang="de">Tageslicht</a>
    	<a lang="en">Artificial</a>

 So I call the normal variables
 with <xsl:value-of select="$variablename/a [@lang = $lang] />
 and the complex ones with
 with <xsl:value-of select="$variablename/a [@code = $code]/a [@lang = $lang]

It was a bit tricky to get around the xsl:include/xsl:import problem, as the
stylesheets are modular and my parser insisted that I have to include/import
the external file into all sub-stylesheets which then in turn leads to
problems with precedence.

Three questions actually:

1. Why does the parser insist on me declaring the variables in each separate
stylesheet, when he works on the parent stylesheet where the text variable
stylesheet is incuded as a top-level element?
The same doesn't happen with <xsl:param name=lang> which is only declared in
the top level stylesheet.

2. Someone metionend a while ago that it is better to avoid variables as they
create result tree fragments. Is there a better way to do this?

3. The XMP data sometimes contains language-sepcific data in elements of the
type lang alt, e.g.

               <rdf:li xml:lang="x-default">Pferde bei der
               <rdf:li xml:lang="en">Horses crossing a stream</rdf:li>

Is there a way to get either my specified language or - if that is not present
- the 'language' x-default?

 The following works but doing this for a lot of elements makes it rather
($lang is passed as a global parameter when saxon is called)

test="rdf:Description/dc:rights/rdf:Alt/rdf:li/@xml:lang = $lang">
select="rdf:Description/dc:rights/rdf:Alt/rdf:li[@xml:lang = $lang]"/>
                                = 'x-default']"/>

Thanks for any suggestions that might help.


Current Thread