Subject: Re: [xsl] is the variable really out of scope?? From: "bix xslt" <bix_xslt@xxxxxxxxxxx> Date: Fri, 06 Dec 2002 00:27:19 +0000 |
From: Gunther Schadow <gunther@xxxxxxxxxxxxxxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] is the variable really out of scope?? Date: Thu, 05 Dec 2002 18:48:45 -0500
> I read through the faq and tried to find an answer to the scope issue. > I found that the faq mentions that a variable within a choose tatement > has a scope confined to that xsl element. However, it does not mention > the scope of the variables external to the xsl element.
For all I know, a variable's scope is limited to the element of which
the variable element is a direct child, and all descendents of that
element. A variable binding can never cross to a sibling or be passed to an ancestor. That's just the way it is.
But I can't quite see what your problem is, because in your code below, you properly wrap the choose statement inside the variable statement, so that you will have the variable in scope after that. I may be missing something, but what you list there should work in principle.
Is there a better way for me to tackle this problem other than creating three separate templates for my choose statement?
I can only see two choose statements, one for w and one for h. Although, you don't handle your cases according to your pseudo code :-)
If you want only one choose statement you may find this more pleasant:
<xsl:variable name="wh"> <xsl:choose> <xsl:when test="..."> <pair w="..." h="..."/> </xsl:when> <xsl:when test="..."> <pair w="..." h="..."/> </xsl:when> <xsl:when test="..."> <pair w="..." h="..."/> </xsl:when> <xsl:otherwise> <pair w="..." h="..."/> </xsl:otherwise> </xsl:choose> </xsl:variable>
<xsl:variable name="w" select="$wh/pair/@w"/> <xsl:variable name="h" select="$wh/pair/@h"/>
Please look specifically at the 'w' and 'h' variables and their updates based on 'k' and 'i'. To help clarify my problem, I have provided my xsl script:
<xsl:template match="/"> <xsl:call-template name="calcOpt" /> </xsl:template>
<xsl:template name="calcOpt"> <xsl:param name="N" select="23" />
<!-- pseudo-code N = value in s = sqrt(N) k = s mod 1 // fractional portion of square root i = s - k
if 0 < k < 0.5 w = i h = i+1 else if k >= 0.5 w = i+1 h = i+1 else w = i h = i -->
N = <xsl:value-of select="$N" /><br />
<xsl:variable name="s">4.79</xsl:variable> s = <xsl:value-of select="$s" /><br />
<xsl:variable name="k" select="$s mod 1" /> k = <xsl:value-of select="$i" /><br />
<xsl:variable name="i" select="$s - $k" /> i = <xsl:value-of select="$k" /><br />
<xsl:variable name="w"> <xsl:choose> <xsl:when test="($k > 0.5) and ($k < 0.5)"> <xsl:value-of select="$i+1" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$i" /> </xsl:otherwise> </xsl:choose> </xsl:variable> w = <xsl:value-of select="$w" /><br />
<xsl:variable name="h"> <xsl:choose> <xsl:when test="($k = 0)"> <xsl:value-of select="$i" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$i+1" /> </xsl:otherwise> </xsl:choose> </xsl:variable> h = <xsl:value-of select="$h" /><br /> </xsl:template>
Thanks in advance, Bix
-- Gunther Schadow, M.D., Ph.D. gschadow@xxxxxxxxxxxxxxx Medical Information Scientist Regenstrief Institute for Health Care Adjunct Assistant Professor Indiana University School of Medicine tel:1(317)630-7960 http://aurora.regenstrief.org
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] is the variable really ou, Michael Kay | Thread | [xsl] XSL Help!!, Chandra - |
Re: [xsl] please help with date for, SAL ROSALES | Date | RE: [xsl] XSL Help!!, Chandra - |
Month |