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

Re: multilanguage support easily or including xml data dynam

Subject: Re: multilanguage support easily or including xml data dynamically
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 8 Jun 2000 01:12:15 -0600 (MDT)
asp xml multilanguage
> I have a report to do with multilanguage support. It's designed this 
> way:
> 
> XML-Number-Data + XSL --> HTML
> 
> Now, I would like to pass a parameter to maybe an ASP, maybe to 
> the XML directly (I appreciate advices!), to select a language, let's 
> say English :).
> Now this should happen:
> 
> 1.) open XML-Number-Data
> 2.) include chunk of language-data properly (e.g. ENGLISH.XML)
> 3.) label the data correctly via XSL and 
> 4.) create HTML.
> 
> Do I need a scripting language like JScript for this? I would like to 
> use as much pure XML/XSL as possible.

You can use pure XML/XSLT, although not by dynamically selecting from a
master file of all local language info, not dynamically including just the
language you need. A very brief example to demonstrate principles:

<?xml version="1.0"?>
<!-- this is XMLNumberData.xml -->
<XMLNumberData>
  <numberData desc="albedo">0.39</numberData>
  <numberData desc="pi">3.1415926</numberData>
</XMLNumberData>

<?xml version="1.0"?>
<!-- this is LanguageData.xml -->
<!-- forgive my completely made-up Spanish! -->
<phrases>
  <phrase key="albedo" xml:lang="en">The albedo of the earth is: </phrase>
  <phrase key="albedo" xml:lang="es">El albedo de la terra es: </phrase>
  <phrase key="pi" xml:lang="en">The value of pi is: </phrase>
  <phrase key="pi" xml:lang="es">El valor de pi es: </phrase>
</phrases>

<?xml version="1.0"?>
<!-- This is LangTest.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" indent="yes"/>
  <xsl:param name="LanguageSelected" select="'en'"/>
  <xsl:variable name="phrases" select="document('LanguageData.xml')/phrases"/>

  <xsl:template match="/">
    <Result>
      <xsl:apply-templates select="XMLNumberData/numberData"/>
    </Result>
  </xsl:template>

  <xsl:template match="numberData">
    <xsl:value-of select="concat('&#xA;',$phrases/phrase[@key=current()/@desc and lang($LanguageSelected)],.)"/>
    <!-- note instead of lang($foo) I could've said @xml:lang=$foo -->
  </xsl:template>
</xsl:stylesheet>


Select the desired language by passing a parameter to the stylesheet,
using the mechanism your XSL processor allows. Default will be 'en'.

Example with Saxon:
  saxon XMLNumberData.xml LangTest.xsl LanguageSelected=es

Output:

<?xml version="1.0" encoding="utf-8" ?>
<Result>
El albedo de la terra es: 0.39
El valor de pi es: 3.1415926</Result>


I would have tried to use <xsl:key/> and key() to make the phrase
selection more efficient, but I couldn't get it to work with the separate
LanguageData document.

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.