xsl-list
[Top] [All Lists]

is the variable really out of scope??

2002-12-05 15:53:14
All,

I have the following problem defined by microsoft IE:
  the variable 'i' is undefined and may be out of scope


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 statement has a scope confined to that xsl element. However, it does not mention the scope of the variables external to the xsl element.

Is there a better way for me to tackle this problem other than creating three separate templates for my choose statement? 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 &gt; 0.5) and ($k &lt; 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

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>