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

Re: Assignment no, dynamic scoping si (was: Re: RE: Wi

Subject: Re: Assignment no, dynamic scoping si (was: Re: RE: Wishes for XSL revisions ...
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 2 Jan 2002 01:40:31 -0800 (PST)
disadvantage in dynamic scoping
Gunther Schadow <gunther at aurora dot regenstrief dot org> wrote:

[snip]

| Here is Terje Norderhaug's use case again for your convenience:

> Being able to simplify the stylesheet by removing repeated parameter
> passing is reason enough for me. However, I have also missed variables
> with dynamic scope when extending predefined stylesheets.
> 
> Dynamic scoped variables may reduce the redundancy between imported
> and importing stylesheets, with associated benefits. It makes
> imported/importing stylesheets less dependent on each other by
> allowing passing of values between templates in a stylesheet without
> demands on the templates in the other stylesheet.
> 
> Say you have a stylesheet "book.xsl" containing templates to process
> the various element types in a book (e.g. book, chapter, paragraph,
> ...) where each template applies templates recursively, like this:
> 
> <xsl:template match="chapter">
>   <fo:block>
>     <xsl:apply-templates/>
>   </fo:block>
> </xsl:template>
> 
> Consider the case that you need to make a stylesheet that imports a
> third party "book.xsl" then overrides its templates for 'book' and
> 'paragraph' elements with custom processing but with a minimum of
> duplication. For some reason, you would like to pass a parameter from
> the 'book' template to the 'paragraph' template.
> 
> Unfortunately, today this requires that you duplicate and modify the
> 'chapter' template (and possibly others) from the "book.xsl"
> stylesheet to pass along the parameter. You end up with a stylesheet
> that contains most or all of the imported stylesheet.
> 

Duplicating and modifying the 'chapter' template (and possibly others) ***is not
required***.

Just declare a global variable and access it in the 'paragraph' template.

One may argue that within the 'book' template the necessary value can be obtained
"dynamically", while the value of a global variable is "static". This is clearly not
true, as any variable (global included) can have templates instantiated/called
within its body in order to define its value.

> With support for dynamic scope, the 'book' template would be able to
> bind variables that are visible for the 'paragraph' template without
> requiring modifications of other templates in "book.xsl".

As pointed out above, this is also possible ***without support for dynamic scope***
by using a global variable.

Another disadvantage of dynamic-scoped variables is that separating and making
remote the definition of a parameter/variable from its reference/use may present
difficulties to its type-checking.

Also, any such separation/remoting makes the code more difficult to understand and
maintain.

Cheers,
Dimitre Novatchev.




__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

 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.