[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: variable question

Subject: RE: variable question
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Wed, 29 Dec 1999 15:23:59 -0700
RE: variable question
>   <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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.