RE: [xsl] Language-specific output

Subject: RE: [xsl] Language-specific output
From: "Nathan Young -X \(natyoung - Artizen at Cisco\)" <natyoung@xxxxxxxxx>
Date: Wed, 1 Feb 2006 12:31:05 -0800
Hi.

Our systems are all still tied to XSL 1.0 (with no nodeset extensions)
so I can't use variables the way you do in your example.

Instead we use the document function to get what we call the dictionary.

The language specific values are stored in an xml file:

<dictionary>
  <bundle language="english">
    <term key="TTitle">XMP Abstract for the file</term>
    ... other english terms
  </bundle>
  <bundle language="german">
    <term key="TTitle">XMP Steckbrief der Datei</term>
    ... other german terms
  </bundle>
</dictionary>


Then at the top of your XSL:

	<xsl:param name="language"/>
	<xsl:variable name="dictionary"
select="document('path/to/dictionary/xml')/dictionary/bundle[@language=$
language]"/>

Then to get the values:

<xsl:value-of select="$dictionary/term[@key='TTitle']"/>

Terms of course could have more complex structure as needed.


------------->Nathan


.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:
||:.

Nathan Young
CDC Site Dev->Interface Development Team
A: ncy1717
E: natyoung@xxxxxxxxx

> -----Original Message-----
> From: cavecatem@xxxxxxxxxxxxx [mailto:cavecatem@xxxxxxxxxxxxx]
> Sent: Wednesday, February 01, 2006 7:32 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Language-specific output
>
> Hi all,
>
> I'm working on a stylesheet that transforms XMP-data to a
> nicely layouted HTML file.
> 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"; version="2.0">
>     <xsl:variable name="TFilename">
>         <a lang="de">Datei: </a>
>         <a lang="en">File: </a>
>     </xsl:variable>
>     <xsl:variable name="TTitle">
>         <a lang="de">XMP Steckbrief der Datei </a>
>         <a lang="en">XMP Abstract for the file </a>
>     </xsl:variable>
>     <xsl:variable name="TExifTitle">
>         <a lang="de">EXIF-Daten</a>
>         <a lang="en">EXIF-Data</a>
>     </xsl:variable>
>     <xsl:variable name="TExposureTime">
>         <a lang="de">Belichtungszeit [s]</a>
>         <a lang="en">Exposure time [s]</a>
>     </xsl:variable>
>
>       <xsl:variable name="lightsource">
>       <a code="1">
>       	<a lang="de">unbekannt</a>
>      	 <a lang="en">unknown>/a>
>       </a>
>     <a code="1">
>     	<a lang="de">Tageslicht</a>
>     	<a lang="en">Artificial</a>
>     <a>
>  ...
>  </xsl:variable>
>
>  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.
>
>         <dc:description>
>             <rdf:Alt>
>                <rdf:li xml:lang="x-default">Pferde bei der
> Bachueberquerung</rdf:li>
>                <rdf:li xml:lang="en">Horses crossing a stream</rdf:li>
>             </rdf:Alt>
>
> 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 slow.
> ($lang is passed as a global parameter when saxon is called)
>
>                    <xsl:choose>
>                         <xsl:when
> test="rdf:Description/dc:rights/rdf:Alt/rdf:li/@xml:lang = $lang">
>                             <xsl:value-of
> select="rdf:Description/dc:rights/rdf:Alt/rdf:li[@xml:lang = $lang]"/>
>                         </xsl:when>
>                         <xsl:otherwise>
>                             <xsl:value-of
> select="rdf:Description/dc:rights/rdf:Alt/rdf:li[@xml:lang
>                                 = 'x-default']"/>
>                             </xsl:otherwise>
>                     </xsl:choose>
>
>
> Thanks for any suggestions that might help.
>
> Regards
> CJ

Current Thread