Rough explanation of partial application (Was: Re: Re:
Dear Laura, Dynamic scoping was discussed at length on this list in the first days of January. There was also a proposal for implementing DS in XPath/XSLT 2.0, which was submitted to the corresponding W3 WG(s). What I thought you were after was to be able to (dynamically) set the values of a set of variables, to be used by a set of templates, without having to pass these values as parameters on every template instantiation, and without making this information "global" (accessible also to other templates, that do not belong to the specific set of templates that should have access to the set of variables). How to do this is described in: "Dynamic Functions using FXSL: Composition, Partial Applications and Lambda Expressions" http://www.topxml.com/xsl/articles/df Very roughly speaking, the idea is to treat the templates you're interested in as functions (just read the article "The Functional Programming Language XSLT - A proof through examples" http://www.topxml.com/xsl/articles/fp/ ) Let's say your template is a function: f(x, y, z) = x * y * z but during the transformation at some point before ever evaluating f(), you know that the values of x and y are 2 and 3, and are not going to change during the whole transformation. Then, you can dynamically create a new function: g(z) = 2 * 3 * z and evaluate g(z) in all places where you'd eveluate f(x, y, z). What you achieve is: - you work with a much simpler function g(z) - g(z) has only one argument, you don't need to pass x and y around all the time. This is potentially more efficient, especially in the case when g() is to be evaluated recursively. - the values of x and y are only accessible inside g(), they do not pollute the global scope for variables. Eliminated is any possibility for name-clashes and/or errors because of similar names of global variables. - you cannot pass f() as a parameter to another function, which expects this parameter to be a function with only one argument. In this case, you can create g(z) from f(x, y, z) and pass g(z) as the value for the required parameter. I'd be glad to answer any further questions you might have. Cheers, Dimitre Novatchev. "Laura Jenkins" <xsl_list at hotmail dot com> wrote: Dear Dimitre.. Could you please put some more light into the following lines you put?? >I think that using a partial application of a function is a complete >and better solution to the so called "dynamic scoping" problem.. Could you please let me know any reference documents that i may refer to do that?? I havent got a clue of how to do that. laura >From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >Subject: Re: Re: variable definition reuse >Date: Fri, 22 Mar 2002 11:10:48 -0800 (PST) > > > > 1. it is possible to do define element specific variables in a > > > different file?? > > > > Not through XSLT means. By definition, element-specific variables are > > local to the place where you're processing the element. The only > > variables that you can share across stylesheets are global variables. > > If you were only interested in (for example) the exp-date element > > child of the first Product in your file, then it would be fine. > > > > You could, however, do this through entities. > >Hi Jeni, > >A better approach is to treat the template that processes a specific >node as function and to produce a partial application of this function, >in which a number of parameters have been bound to specific values. >This bindings will remain through the lifetime of the partial >application (an RTF) and will be in place every time it is >instantiated. > >I think this is very close to (or maybe exactly) what Laura wishes to >have. > >Also note, that the binding are produced at runtime and could be >dynamic, depending on specific conditions that are unknown in advance. >This is another advantage over the entities approach. > >I think that using a partial application of a function is a complete >and better solution to the so called "dynamic scoping" problem. > >Currying and partial application are available as part of the FXSL >functional programming library. > __________________________________________________ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards® http://movies.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format