[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How can I create a variable with a variable access

Subject: Re: 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
name access
Hi,

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
;

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

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 ;

<text>
   <searchButton>Suchen</searchButton>
   ...
</text>

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


Alex
--
"Ultimately, all things are known because you want to believe you know."
                                                         - Frank Herbert
__ http://shelter.nu/ __________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.