[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 XSL revisions ...
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 2 Jan 2002 10:49:06 -0800 (PST)
type checking during dynamic scope
Gunther Schadow <gunther at aurora dot regenstrief dot org> wrote:

[snip]

> So, in a world with dynamic scoping / implicit parameters,
> lowlyweb.org would do this:
> 
> <xsl:stylesheet id='urn:lowlyweb.org:onlinebook'>
> 
> <xsl:import href='http://bigbucksbooks.com/onlinebook.xsl'/>
> 
> <xsl:template match='section'>
>    ...
>    <xsl:apply-templates>
>      <xsl:with-implicit-param name='source' select='@source'/>
>    </xsl:apply-templates>
>    ...
> </xsl:template>
> 
> <xsl:template match='paragraph'>
>    <xsl:implicit-param name='source' select='@source'/>
>    <p class='$source'>
>      <xsl:apply-templates/>
>    </p>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> This template would only touch the section and paragraph elements
> of bigbucksbooks and would leave everything else untouched.
> The implicit parameter source is bound to the @source value given
> in the document for everything nested within that section. Now,
> most of this stuff doesn't care, until we get down to the paragraph
> element that now has this implicit parameter available no matter
> how many things were passed through.
> 
> I cannot see how to do that with global variables as you suggest,
> because that book contains many sections and needs to switch
> between the different sources all the time per each section.
> 
> I can see how one can do the same thing with explicit parameters,
> which however, requires modifying all of bigbucksbooks templates
> for table, list (and then: frame, box, float, imagetitle,
> rotated-text, ...).
> 
> So, if you could show me how this can be done without changing the
> whole thing, I am all ears.

Certainly. This is very simple using XSLT. You even don't have to modify the
"section" template neither do you need a global variable. In the "paragraph"
template declare and use the following local variable:

<xsl:variable name="source" select="ancestor::section[1]/@source"/>


> 
> You also note:
> 
> > 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. 
> 
> 
> I definitely agree with you that these are concerns with
> simple dynamically scoped variables. When examining just
> one lexical scope, they appear as free variables and one
> doesn't know what they are.
> 
> In my proposal (submitted under Request for ...) and in this
> example, however, you see that implicit parameters are
> declared just as explicit parameters in their lexical
> scope. So you know exactly what they are (of course their
> actual binding will be dynamic.)
> 
> If there were any type checking with XSLT (say, if XSLT were
> a strongly typed language) the type would be mentioned in
> the declaration everywhere and could be validated throughout
> the stylesheet at compile-time. So it's safe.

Type-checking many descendents of a node in a tree is much more difficult than
type-checking the formal/actual types in a direct call/instantiation (which is just
a segment compared to the tree in the former case). As Mike mentioned, most probably
this would be prohibitively more costly than the added value the feature proposed by
you may bring. Actually, until now you haven't been able to provide a single
example, where such added value is apparent.

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.