Loading ...
Sorry, an error occurred while loading the content.
 

Re: [XSL-FO] xsl:variable out of scope error???

Expand Messages
  • Oleg Tkachenko
    ... No, you can t do this. Scope of local variable is following siblings and their descendants only and it goes out of scope at the end tag of its parent
    Message 1 of 2 , Aug 30, 2001
      sg_goli@... wrote:
      > <xsl:for-each select="/MainTag/TagA">
      >
      > <xsl:variable name="AIName1" select="AI_Name"/>
      >
      >
      > <xsl:for-each select="/MainTag/TagB">
      > <xsl:variable name="AIName2" select="AI_Name"/>
      > <xsl:choose>
      >
      > <xsl:when test="$AIName1=$AIName2">
      >
      > <xsl:variable name="blnflag">
      > <xsl:value-of select="0"/>
      > </xsl:variable>
      > </xsl:when>
      >
      > <xsl:otherwise>
      > </xsl:otherwise>
      > </xsl:choose>
      > </xsl:for-each>
      >
      >
      >
      > <xsl:if test="$blnflag!='0'">
      > <!-- do something -->
      >
      > </xsl:if>
      >
      > </xsl:for-each>
      >
      >
      > I get out of scope error on this line
      >
      > <xsl:if test="$blnflag!='0'">
      > I want to store a value into a variable in the inner loop and then
      > use it within the outer loop. Is this possible at all??
      No, you can't do this. Scope of local variable is following siblings and
      their descendants only and it goes out of scope at the end tag of its
      parent element.
      But I believe you don't need it - look at this:
      <xsl:for-each select="/MainTag/TagA">
      <xsl:variable name="AIName1" select="AI_Name"/>
      <xsl:variable name="blnflag">
      <xsl:for-each select="/MainTag/TagB">
      <xsl:variable name="AIName2" select="AI_Name"/>
      <xsl:choose>
      <xsl:when test="$AIName1=$AIName2">
      <xsl:value-of select="0"/>
      </xsl:when>
      <xsl:otherwise/>
      </xsl:choose>
      </xsl:for-each>
      </xsl:variable>
      <xsl:if test="$blnflag!='0'">
      <!-- do something -->
      </xsl:if>
      </xsl:for-each>

      Variable blnflag is in scope of <xsl:if> element and all right.
      So, shortly, instead of
      <xsl:choose>
      <xsl:when test="smthing">
      <xsl:variable name="var" select="smthing"/> </xsl:when>
      </xsl:choose>
      try
      <xsl:variable name="var">
      <xsl:choose>
      <xsl:when test="smthing">
      <xsl:text>0</xsl:text>
      </xsl:when>
      </xsl:choose>
      </xsl:variable>

      --
      Oleg Tkachenko
      Multiconn International
    Your message has been successfully submitted and would be delivered to recipients shortly.