RE: [xsl] Can i assign value to a variable and used it in different template

Subject: RE: [xsl] Can i assign value to a variable and used it in different template
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 21 Sep 2004 09:54:54 +0100
> I have the following template 
> 
> <xsl:template name="process-style">	
> 	<xsl:if test="normalize-space($name)='border' and self::table">
> 		<xsl:variable name="bordervalue" select='"$value"'/>
> 	</xsl:if>		
> </xsl:template>

This is pretty confused. Firstly, it can only work if $name is a global
variable, which doesn't match your description. Secondly, $value looks at
first sight like an XPath variable reference, but it is actually just a
string, because you have put it in quotes. Thirdly, you are declaring a
variable bordervalue which is never referenced, and can never be referenced,
because it goes immediately out of scope. Fourthly, if this template only
does anything when the context node is a table element, why haven't you made
it a match="table" template rule?
> 
> Actually i am used this template for processing inline 
> style.(above is a
> part of that).
> name variable contains the attribute name present in style 
> attribute.My aim
> is to
> check whether the name is border,then i store it value to 
> some variable.I
> want to use 
> this variable in  some other templates.

The scoping rules for variables mean you can't do that (just like most other
languages). You need to declare the variable inline, you can't call a
template to do it. You can then pass its value to other templates as a
parameter.

Michael Kay
http://www.saxonica.com/

Current Thread