Re: [xsl] How can I create a variable with a variable access path?

Subject: Re: [xsl] How can I create a variable with a variable access path?
From: Alexander Johannesen <alexander.johannesen@xxxxxxxxx>
Date: Tue, 6 Dec 2005 11:05:05 +1100

Ferdinand Soethe <xsl-list@xxxxxxxxxx> wrote:
> For an international application I'd like to store all texts in a
> construct like
> <xsl:variable name="AllTexts">
>   <!-- german language texts -->
>   <de>
>     <searchButton>Suchen</searchButton>
>   </de>

First, in XSLT 1.0 you cannot access result-tree fragments through
XPath, but if you're using XSLT 2.0 you're alright. However, I'd
strongly advice to put all this stuff in an external XML file, such as

   <searchButton   de="Suchen"     en="Search"   />
   <findButton     de="Finden"     en="Find"     />
   <clickButton    de="Drucken"    en="Click"    />

And then you can use this in your stylesheet as ;

   <xsl:param name="language">de</xsl:param>
   <xsl:variable name="AllTexts" select="document('text.xml')/*" />

   <xsl:value-of select="$AllTexts/searchButton/@*[name()=$language]" />

To further this, to make the XSLT look nicer it would be good to acces
the language texts as ;

   <xsl:value-of select="$AllTexts/searchButton" />

and you could do that by having your languages in separate XML files
as text_en.xml and text_de.xml, and ;

   <xsl:variable name="AllTexts"
select="document(concat('text_',$language,'.xml'))/*" />

and have the format of your text_de.xml (for example) file as ;


Many options here, really. Depends on how complex your needs are and so

"Ultimately, all things are known because you want to believe you know."
                                                         - Frank Herbert
__ __________________________________________________

Current Thread