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

Using a parameter in a condition

Subject: Using a parameter in a condition
From: Ian Lang <ianplang@xxxxxxxxx>
Date: Mon, 23 Feb 2004 23:11:59 -0800 (PST)
xsl return parameter
I am implementing a look up table for localizable
strings.  I have a string table that looks like this:
<?xml version="1.0"?>
<strings>
  <string key="String.One">First String</string>
  <string key="String.Two">Second String</string>
</strings>

I do this to load the string table in my main xslt:
  <!-- Load the string table -->
  <xsl:variable name="stringTable"
select="document($stringTableFileName)"/>
where $stringTableFileName is a parameter to the style
sheet.

To test things I used variables like this:
<xsl:variable name="title"
select="$stringTable/strings/string[@key='String.One']"/>

Which worked but I wanted to instead call a template
passing it the key so I can centralize the lookup and
provide the ability to return a string "!<key>!" if
the key could not be found.  So I wrote:
  <xsl:template name="getLocalizedString">
    <xsl:param name="key"/>
    <xsl:variable name="lookupString"
select="$stringTable/strings/string[@key=$key]"/>
    <xsl:choose>
      <xsl:when test="lookupString != ''">
        <!-- Return the found string -->
        <xsl:value-of select="$lookupString"/>
      </xsl:when>
      <xsl:otherwise>
        <!-- Return a string indicating what key could
not be found -->
        <xsl:text>!</xsl:text><xsl:value-of
select="$key"/><xsl:text>!</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

The trouble is that no matter how I write the
definition for lookupString and no matter how I pass
the parameter key I cannot get it to work.  I either
get returns of "!!" or "!<key>!" but never the string
I want.  This seems like and FAQ but I cannot seemt to
find what I am looking for.

Any help apprciated,

IL



__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

 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.