xsl-list
[Top] [All Lists]

RE: newbie question

2002-10-29 04:48:12
|My problem is the variavle I have defined in if statement is not
|visible to the table.
|Is there any way I can just declare a variable somewhere and
|assign a value to it where ever I want??

the problem is that you have to take scope into account:

|<xsl:if test="//request/param[(_at_)name='action']='Edit'">
|       <xsl:variable name="uContact>
|               <xsl:value-of select="./selection/email"/>
|       </xsl:variable>
|</xsl:if>

will create a variable within the scope of <xsl:if />.

what you need to do is define the variable outside the <xsl:if /> block, and
put the <xsl:if  /> inside the variable declaration like this:

<xsl:variable name="uContact">
        <xsl:if test="//request/param[(_at_)name='action']='Edit'">
                <xsl:value-of select="./selection/email"/>
        </xsl:if>
</xsl:variable>

this now means that you have a variable called 'uContact' which, when
//request/param[(_at_)name='action']='Edit', will be equal to ./selection/email.

if you need to define this variable as having multiple values based on
multiple tests, you can use something like this:

<xsl:variable name="uContact">
        <xsl:choose>
                <xsl:when test="//request/param[(_at_)name='action']='Edit'">
                        <xsl:value-of select="./selection/email"/>
                </xsl:when>
                <xsl:when ... />
                <xsl:otherwise>
                        <xsl:value-of 
select="//request/param[(_at_)name='email']"/>
                </xsl:otherwise>
        </xsl:choose>
</xsl:variable>

in either case, you can then use this variable while it's in scope like
this:

<input type="text" name="email" size="25" maxlength="25"
value="{$uContact}"/>

it's worth remembering that the <xsl:when /> clauses will be evaluated in
order of occurence, so the first one it matches on will be the value, and
the otherwise will be executed if none are matched.

hope that helps,

b

|-----Original Message-----
|Sent: 29 October 2002 11:17
|Subject: [xsl] newbie question
|My requirement is to define a variable depending on the mode -
|edit or create. What I am doing is:
|           <xsl:variable name="uContact"><xsl:value-of
|select="//request/param[(_at_)name='email']"/></xsl:variable>
|<xsl:if test="//request/param[(_at_)name='action']='Edit'">
|       <xsl:variable name="uContact><xsl:value-of
|select="./selection/email"/></xsl:variable>
|And I must be able to use the above defined value in a table
|  <tr>
|     <td>Contact:</td>
|    <td><input type="text" name="email" size="25" maxlength="25"
|value="{$uContact"/></td>
|  </tr>
|My problem is the variavle I have defined in if statement is not
|visible to the table.
|Is there any way I can just declare a variable somewhere and
|assign a value to it where ever I want??
|Ex:  var x= "";
|       if (.....)
|         x="I am in if";
|       else
|         x="i am in else";
|I am not a xslt person and really struggling over this seemingly simply
|thing. Any help would be greatly appreciated.
|thanks
|-M


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



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