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

Re: Variable scope when using imported stylesheets

Subject: Re: Variable scope when using imported stylesheets
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 24 Aug 2004 15:59:19 +0100
xml variable scope
> 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[67]">
]>
<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[67]"/>


....

<xsl:apply-templates select="a/b/c/d/e/f/g/h/i/j/k/l/m[67]"/>


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
________________________________________________________________________

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.