Subject: RE: [xsl] Using a parameter in a condition From: "Michael Kay" <mhk@xxxxxxxxx> Date: Tue, 24 Feb 2004 08:58:34 -0000 |
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: [xsl] 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Using a parameter in a condit, Ian Lang | Thread | Re: Fw: [xsl] Using a parameter in , Ian Lang |
[xsl] question count some nodes, Markus Hanel | Date | RE: [xsl] xml:base, Michael Kay |
Month |