xsl-list
[Top] [All Lists]

RE: Scope of variables

2003-05-08 12:20:21
[ Karl J. Stubsjoen]

1)  If I define a variable at the top of a template rule and 
then later try
to update the value of this variable later down in the 
template, I always
get the error "Can't define variable twice...".  So how do 
you reassign a
value to a variable.

Karl, Google is your friend - the first hit with this search is a useful
page -

xslt faq variable scope

This first hit is 


2) About scope:  Within a for-each loop I have a choose.  In 
the choose I
have a single test and an otherwise.  The result of the 
choose is setting
the value of a variable.  Just below this choose logic I am 
referencing the
value but am getting the error "A reference to variable or parameter
'currentVAL' cannot be resolved".  Where did I lose scopE on 
this variable
(currentVAL)?
Here is a bit of the code from this template:

BEGIN SNIPPET...

 <xsl:for-each select="$xmTmplt/FLDS/FLD">
 <xsl:variable name="innerFLD" select="@name" />
    <!-- DETERMINE IF TEMPLATE DOC HAS A DEFAULT VALUE SET -->
        <xsl:choose>
     <xsl:when test="'a'='a'">
      <xsl:variable name="currentVAL">TESTING</xsl:variable>
        </xsl:when>
        <xsl:otherwise>
      <xsl:variable name="currentVAL" 
select="$outerCurrent/@*[name() =
$innerFLD]"/>
        </xsl:otherwise>
        </xsl:choose>
    <xsl:if test="@viewable='true' or not(@viewable)">
           <tr>
            <td><!-- lookup text for display in xml template -->
            <xsl:value-of select="@text"/></td>
         <td>
            <xsl:choose>
                <xsl:when
test="$xmTmplt/FLDS/FLD[(_at_)name=$innerFLD]/@edit='true'">
                <!-- make edit fields -->
             <xsl:call-template name="MAKE_INPUT_BOX">
                <xsl:with-param name="input_name"><xsl:value-of
select="$innerFLD"/></xsl:with-param>
                <xsl:with-param name="input_value"><xsl:value-of
select="$currentVAL"/></xsl:with-param>

.... END SNIPPET

Thanks for the help,
Karl


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



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



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