Subject: RE: variable question From: Mike Brown <mbrown@xxxxxxxxxxxxx> Date: Wed, 29 Dec 1999 15:23:59 -0700 |
> <xsl:template match="MYROOT"> > <xsl:variable name="BusinessPartnerContract"> > This is a business partner contract. > </xsl:variable> > ... > </xsl:template> As you have discovered, a variable assignment only has scope along the descendant and following-sibling axes. To make the variable available for use in another template, you have two options: 1. Set it at the top level, somewhere between the xsl:stylesheet and the first xsl:template. This makes it available to all templates, but is bad if it needs to have different values at different times. 2. Make sure it is in scope at the point where you call or apply the other templates, and pass it as a parameter. <xsl:variable name="foo" select="'some string'"/> <xsl:call-template name="pageHeader"> <xsl:with-param name="bar" select="$foo"/> </xsl:call-template> ... <xsl:template name="pageHeader"> <xsl:param name="bar"/> <xsl:value-of select="$bar"/> </xsl:template> This can be inconvenient but it does ensure that each template operates independently of the others; with the exception of parameters that must be explicitly passed and received, one template can't set a state or have a side effect that another template can be aware of. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
test post, costempd | Thread | RE: variable question, sara . mitchell |
Re: xsl:variable question, Steve Tinney | Date | [no subject], David J. Kim |
Month |