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

Re: Need help with using lookup table and string tran

Subject: Re: Need help with using lookup table and string translation
From: Sebastian Prehn <sebastian.prehn@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 May 2009 15:39:05 +0200
Re:  Need help with using lookup table and string  tran
Hi!

some short thoughts:
You need a template that matches all <trs> elements
In that template select the text node and store the text value in a variable. lets call it $key
then select /trans/tr_string[@str=$key]/ru/text()
if it isnot empty return it otherwise select the en version.
this can be done with a if then else expression

regards 
Sebastian



On Mon, 11 May 2009 09:18:58 -0400, Dmitri Snytkine <d.snytkine@xxxxxxxxx> wrote:
> Hello! I just started working with xslt a couple of days ago.
> It's still very new to me, even though I have over 5 years experience
> with php and javascript, which at least makes it relative easy to
> learn xslt, but I still can use good advice.
> 
> This is what I want to acheive:
> 
> I am developing a milti-lingual site, and want the transformations
> dont by the browser. For that I am including an xml of translations in
> a form of a lookup table inside the xsl template file, like this:
>  <trans:tr page_id="global">
>         <tr_string str="recent_albums">
>             <en>
>                 Recent Albums
>             </en>
>             <ru>
>                 PP>P2QP5 P0P;QP1P>P<Q
>             </ru>
>         </tr_string>
> 
>                 <tr_string str="welcome">
>             <en>
>                 Welcome to our site
>             </en>
>             <ru>
>                 PP>P1QP> P?P>P6P0P;P>P2P0QQ
>             </ru>
>         </tr_string>
> 
>         <tr_string str="recent_videos">
>             <en>
>                 Recent Videos
>             </en>
>         </tr_string>
> 
> 
>         <tr_string str="recent_images">
>             <en>
>                 Recent Images
>             </en>
>             <ru>
>                 PP>P2QP5 QP>QP:P8
>             </ru>
>         </tr_string>
>     </trans:tr>
> 
> 
> Then inside the xml file I may have strings like this:
> 
> <root>
>     <gv d="en" c="ru" lm="dynamic" sd="member"/>
>     <title>
>         My title
>     </title>
> 
>     <main>
>         <trs>
>             welcome
>         </trs>
>         <recent_images>
>             <div class="recent">
>                 <trs>
>                     recent_images
>                 </trs>
>             </div>
>             <img title="ocean">/img1.jpg</img>
>             <img title="people">/img2.jpg</img>
>             <img title="my dog">/img3.gif</img>
>         </recent_images>
> 
>     </main>
> 
> </root>
> 
> Now how do I make it so that every instance if <trs> tag is replaced
> by value of:
> if tag <tr_string> with value of "str" = <trs> does not exist, then
> return value of <trs> itself
> otherwise:
> find element <tr_string> with value of 'str' = value of <trs>
> and them: if it has child tag named  <ru>, return its value, otherwise
> return the value of <en>
> 
> In other words: if translaion lookup table has this string, then get
> the value or <ru> if it exists and not empty, otherwise fallback to
> value of <en>
> 
> If translation lookup table does not even have this string, then
> return untranslated value.
> 
> Anyway, maybe someone has already done something similar for a
> multilingual site and maybe there is a better way to store the lookup
> table?
> 
> I appreciate if anyone can help me with this.
> 
> Thank you.
--
PLANETS-Webdesign - Web Applications
Sebastian Prehn
Adlerstr. 56, 70199 Stuttgart
www.planetswebdesign.de
PGP keyID: 0x3507AF63

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.