RE: [xsl] newbie question

Subject: RE: [xsl] newbie question
From: Madhavi Thottempudi <madhavi@xxxxxxxxxxxxxxx>
Date: Tue, 29 Oct 2002 12:11:04 +0000
Hi Allan!
Thanks for UR reply. That clears my doubts.
But what if U have too many variables in UR page?? Ex: for a registration form.
Is there any way I can escape filling my page with when-otherwise statements (one for each variable)??


I need to do this check on each variable as,
my form is empty if that's used for adding a profile and it's with values from database if the profile is being edited.
won't one would prefer to do like -


declare all variables;

when (mode=edit)
  assign values to all variables
otherwise
  assign diff values all variables

Any suggestions??

cheers
-M


At 11:48 29/10/2002 +0000, you wrote:
|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[@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[@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[@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[@name='action']='Edit'">
<xsl:value-of select="./selection/email"/>
</xsl:when>
<xsl:when ... />
<xsl:otherwise>
<xsl:value-of select="//request/param[@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[@name='email']"/></xsl:variable>
|<xsl:if test="//request/param[@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


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


Current Thread