Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Language-specific output

From: "cavecatem@-------------" <---------@------------->
To:
Date: 2/1/2006 2:32:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent