Subject: [xsl] 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) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Request for dynamically scope, Gunther Schadow | Thread | Re: [xsl] Re: Assignment no, dynami, Gunther Schadow |
[xsl] Request for dynamically scope, Gunther Schadow | Date | RE: [xsl] Re: XPath incompatibiliti, Michael Kay |
Month |