Re: Variable scope when using imported stylesheets
> Of course, this means I have to insert the variables > declaration in every template that is called in this way. If evaluating the variable is likely to be expensive an alternative is to pass it as a parameter, so after your top level template that is processing your document fragment you evaluate the variable then pass it as a parameter (you would have to declare it and pass it explicty in every template that is used though). Alternatively of course you can use XML entity references which can be used to hold arbitrary fragments of expressions (just as in C you can't hold an expression in a string valued variable but you can use a #Define as that is expanded inline by the pre-processor). If you just want a short way to access the Xpath expression you can do <!DOCTYPE xsl:stylesheet [ <!ENTITY foo "a/b/c/d/e/f/g/h/i/j/k/l/m"> ]> <xsl:stylesheet> .... <xsl:apply-templates select="&foo;"/> .... <xsl:apply-templates select="&foo;"/> here the entity reference will be expanded by the parser before XSLT begins so XSLT will see <xsl:stylesheet> .... <xsl:apply-templates select="a/b/c/d/e/f/g/h/i/j/k/l/m"/> .... <xsl:apply-templates select="a/b/c/d/e/f/g/h/i/j/k/l/m"/> and each of the expressions will be evaluated in the context in which it appears. David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format