cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Newland" <cnewl...@nortelnetworks.com>
Subject XSL variable scope problem
Date Tue, 29 Aug 2000 11:58:39 GMT
Hi,

I'm having scope problems involving xsl:variable:

I want to do the XSL equivalent of the following Java code:
//----------------------------------------------------
String foo;

if (condition == true) {

	foo = "bar";

}

display(foo);
//----------------------------------------------------

The XSL I think I need is:

//----------------------------------------------------

<xsl:variable name="foo"/>

<xsl:if test="@parameter='title'">
	<xsl:variable name="foo"><xsl:value-of
select="@value"/></xsl:variable>
</xsl:if>

<table border="1" cellpadding="0" cellspacing="5">
<tr>
<td><xsl:value-of select="$foo"/></td>
</tr>
</table>
//----------------------------------------------------

I've read in the archives that xsl variables are immutable and this seems to
be true as nothing is displayed in my table cell but if I print the value of
$foo from inside the <xsl:if> then it has the correct value.

If I do not declare the variable before the <xsl:if> then I get a Xalan
exception:

Error found handling the request.
org.apache.xalan.xslt.XSLProcessorException: pattern = '$foo'
VariableReference given for variable out of context or without definition!
Name = foo

Is there a way to do this or do I have the wrong mindset for this problem?

Thanks,

Chris 

--
Chris Newland 
Software Research Engineer 
Advanced IP Services and Management 
Nortel Networks, London Road, Harlow, Essex, CM17 9NA. 
Tel:   +44(0)1279 405165 
Fax:   +44(0)1279 402047 
Email: cnewland@nortelnetworks.com
"This message may contain information proprietary to Nortel Networks 
so any unauthorised disclosure, copying or distribution of its 
contents is strictly prohibited." 
------------------------------------------------------------
Company name: Nortel Networks plc
Company number: 2515751
Company's registered office address: Maidenhead Office Park, 
Westacott Way, Maidenhead, Berkshire SL6 3QH.
------------------------------------------------------------


Mime
View raw message