[xsl] Re: Re: Assignment no, dynamic scoping si (was: Wishes for XSL revisions ...

Subject: [xsl] Re: Re: Assignment no, dynamic scoping si (was: Wishes for XSL revisions ...
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 28 Dec 2001 22:49:44 -0800 (PST)

Recently I gave an example of dynamic creation of new functions. It described a
"store" of variables and their values for a calculator. Maybe this could be helpful?


Dimitre Novatchev.

Gunther Schadow <gunther at aurora dot regenstrief dot org> wrote:

Mike Haarman wrote:

>>There is even a simpler approach using only XSLT: I can make all
>>templates use an argument that is a constructed node-set
>>containing name-value pairs (the dynamic environment) and references
>>to the bindings in this environment would be supported by some
>>xpath selects in that environment node-set.
> Thanks for the insight.  Can the dynamic environment be incorporated into
> the internal subset via parameter entities?  Such a solution does not
> leave interoperability entirely in crutches.

This is what it would take:

all template calls or applies that typically just look like

<xsl:apply-templates select='...'/>

<xsl:call-template name='...'/>

would have to be transformed into:

<xsl:apply-templates select='...'>
   <xsl:with-param name='environment' select='$environment'/>

<xsl:call-template name='...'>
   <xsl:with-param name='environment' select='$environment'/>

and every template

<xsl:template ...>

transformed into

<xsl:template ...>
   <xsl:param name='environment' select='/..'>

The environment would be a node set like this:

<nick>before nack</nick>

with each name being an element and the value bound to the name
a node-set content of the element.

Adding a binding foo='bar' to the environment would be

<xsl:variable name='new-environment-rtf'>
    <xsl:element name='foo'>
      <xsl:copy-of select='$environment'/>
<xsl:apply-templates select='...'>
   <xsl:with-param name='environment'

Then querying the environment for the binding foo would be:


This always picks the first element. This is what does the
shadowing of the old bindings by the new bindings. That's not
strictly necessary, because the old bindings wouldn't have
to be carried along as long as you don't have functional
arguments that depend on old bindings (which I don't see a
way of having in XSLT anyway.) But there is no easy way of
replacing the old bindings that are to be shadowed without
more work, so we can just carry them along.

May be it would be easier to carry the bindings as elements
such as <binding name='foo'>bar</binding> (could be easier
to use with keys or something.) But the principle is the same.

In any event, I don't quite see how parameter entities would
make that much easier. What one would need is macros (ugh)
or just simply an XSLT doing the transforms described above.
In any event, it's a lot of burden to do for routine use
just in case someone wants to have a few dynamically scoped

Do You Yahoo!?
Send your FREE holiday greetings online!

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

Current Thread