Subject: Re: [xsl] Setting a global variable, or using a variable in place of provided XML From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx> Date: Thu, 25 Apr 2002 10:30:26 -0400 |
Local variables do not exist outside their local scope, as you have discovered. There are several approaches you can take. Two I'd think about for myself: 1) Where you are currently writing your xsl:choose statement, you could call or apply a template. The template would do the same thing as your statement, but wouldn't have to duplicated all over the place. Exactly how you would call this template would depend on the context in effect where the call is made, which we can't quite tell from the information you provided. 2) Have a second xml file that contains the string-to-number mapping, and use it as a lookup table, perhaps using a key to speed things up. 1) is a bit simpler, 2) would let you swap different mappings in and out by changing the lookup file. That might be an advantage depending on what you want to accomplish. Cheers, Tom P [dorian dorian] > I'm new to xsl and have run into a problem which I'm > unable to solve on my own. I've been through the faq > and the list archives, but my general inexperience > with xsl prevents me from determining if one of the > faq answers can help me. > > Here's my situation - > > In my XML, I'm provided font sizing information as a > string, rather than a number, e.g. 'small', 'medium', > 'large', etc. > > For example, > > <xsl:value-of select="//template/bodyfont/@size" /> > > Will contain either 'small', 'medium', 'large', etc. > > For specific reasons, I need to declare my font sizes > as numbers, via <font size="1"> to maintain > consistency across the document. > > I'd like to do something similar to - > > <xsl:choose> > <xsl:when test="//template/bodyfont/@size = 'small'"> > <xsl:variable name="bodyfontsize" select="'2'"/> > </xsl:when> > <xsl:otherwise> > <xsl:variable name="bodyfontsize" select="'4'"/> > </xsl:otherwise> > </xsl:choose> > > And later declare font sizes via <font > size={$bodyfontsize}> . Unfortunately, $bodyfontsize > does not appear to persist beyond the closing > xsl:choose. My XSL parser (sablotron) reports that the > variable does not exist. (I've tested this by placing > an <xsl:value-of select="$bodyfontsize" /> after the > closing xsl:choose above.) > > I've tried a few different approaches, but none seem > to work as well as I believe xsl would allow. > > Can anyone point me in the right direction, or offer a > suggestion? I'm generally self-reliant, but in this > case, I don't know enough about xsl to begin to know > where to look. > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Setting a global variable, or, dorian dorian | Thread | RE: [xsl] Setting a global variable, Jarno . Elovirta |
[xsl] Extending xsltproc?, Gary Lawrence Murphy | Date | RE: [xsl] Extending xsltproc?, Michael Kay |
Month |