This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
localization using <xsl:key> help
- To: xsl-list at mulberrytech dot com
- Subject: localization using <xsl:key> help
- From: Mike Engelhart <mengelhart at earthtrip dot com>
- Date: Thu, 09 Mar 2000 14:09:47 -0600
- Reply-To: xsl-list at mulberrytech dot com
Hi
I'm trying to use <xsl:key> to do string lookups for localization. I have
it working using the following setup (i'm using Cocoon w/xalan & xerces to
do the processing) The following three files test.xml, test.xsl,
localization.xml are what I'm using
<!-- localization.xml -->
<?xml version="1.0"?>
<localization>
<word name="_FIRST_NAME">
<translation lang="en">First Name</translation>
<translation lang="es">Nombre</translation>
<translation lang="it">Nome</translation>
</word>
</localization>
<!-- test.xml -->
<?xml version="1.0"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="./test.xsl" type="text/xsl"?>
<page xml:lang="en">
<field>_FIRST_NAME</field>
</page>
<!-- test.xsl -->
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="translate" match="word" use="@name"/>
<xsl:template match="page">
<xsl:for-each select="document('./localization.xml')">
<html><body><h1>
<xsl:value-of select="key('translate','_FIRST_NAME')/translation"/>
</h1></body></html>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Now when run through Cocoon, I get an html page with the output being "First
Name" as an <H1> element as expected. What I want to do is have the key
lookup determine which <translation> element to grab based on the language
attribute. i can't figure out what to put here:
<xsl:value-of select="key('translate','_FIRST_NAME')/translation"/>
to get this done.
Any help would be greatly appreciated.
Thanks,
MIke
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list