|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Using a parameter in a condition
You are clearly supplying the parameter to the template incorrectly, but since you haven't shown us the calling code, it's hard to tell you what's wrong with it. Michael Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Ian Lang > Sent: 24 February 2004 07:12 > To: XSLT List > Subject: Using a parameter in a condition > > > 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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








