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

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

Subject: Re: Re: Assignment no, dynamic scoping si (was: Re: RE: Wishes for XSLrevisions ...
From: terje@xxxxxxxxxxxxxxx (Terje Norderhaug)
Date: Thu, 3 Jan 2002 16:44:29 -0800 (PST)
assignment book template
At 9:40 AM 1/2/02, Dimitre Novatchev wrote:
>Gunther Schadow <gunther at aurora dot regenstrief dot org> wrote:
>| Here is Terje Norderhaug's use case again for your convenience:
>> 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
>Just declare a global variable and access it in the 'paragraph' template.

This assumes that the document contains only one book element. If the document contains more than one 'book' element, you cannot use a global variable as the value may differ for each instantiation of the template that matches 'book'.

To make this more obvious, lets modify the use case so that a book consist of the element types book, part, chapter, paragraph, ... where it is the template for 'part' that want to pass a value to the template for a 'paragraph', as before without duplicating/modifying the template for a 'chapter'. 

>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.

Sure. So in the special case of a template for a document element, global variables can cover the same functionality as a dynamic variable. Nothing new here.

>> 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.

Only in special cases, like when processing the document element.

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

Savvy programmers can use dynamic variables to write code that is *easier* to understand and maintain. It is certainly much easier compared with alternatives such as explicitely maintaining a name/value mapping passed as an argument to all templates (as proposed earlier in this thread). It is the case though that dynamic variables may give novices more roap to hang themself with. 

-- Terje <terje@xxxxxxxxxxxxxxx> | Media Design in*Progress 
   Software for Mac Web Professionals at <http://www.in-progress.com>
   Take Advantage of Server Side XML and XSL with Interaction 3.6!

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.