Re: [xsl] Language-specific output

Subject: Re: [xsl] Language-specific output
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 1 Feb 2006 14:50:36 GMT
                   <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>
 

could be writen

 <xsl:value-of select="rdf:Description/dc:rights/rdf:Alt/(rdf:li[@xml:lang= $lang],rdf:li[@xml:lang= 'x-default'])[1]

or if you know x-default always comes first in the input (if it is
there) you can simplify further to


<xsl:value-of select="rdf:Description/dc:rights/rdf:Alt/rdf:li[@xml:lang=($lang,'x-default')][last()]

I can't really answer your earlier points as it depends what you are
doing. If you have stylesheet that references a variable that isn't
defined, but you only use that stylesheet in combination with another
stylesheet that does declare the variable that shoudl work.

However it might be that your IDE to aid xslt debugging or whatever is
compiling each stylesheet separtately, and this would fail of course.

I wouldn't use lots of variables for this I'd just use one _document_
(or equivaently one variable) something like
<xsl:variable name="stuff>
<a name="TFilename lang="de">Datei:</a>
<a name="TFilename" lang="en">File:</a>
<a name="TTitle">lang="de">XMP Steckbrief der Datei </a>
...




accessed as $stuff/a[@name=$name and @lang=@lang]

(if this list is big, access could be considerably quickened if you also
defiend an xsl:key for these elements.


If you want your sub-stylesheets to be able to be compiled without error
you only need to add

<xsl:variable name="stuff" select="()"/>

to them, this makes the variable declared as an empty list so it will
type check when used in path expressions. It doesn't matter that it's
not the value you want as when you run it this global variable will have
the value from your top most importing stylesheet which is your lookup
table.


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread