[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Re: Incrementing a Global variable


Subject: Re: [xsl] Re: Incrementing a Global variable
From: Mukul Gandhi <mukulw3@xxxxxxxxx>
Date: Thu, 28 Aug 2003 07:08:31 -0700 (PDT)

Hi David,
  Please see my comments below your statements --

--- David Carlisle <davidc@xxxxxxxxx> wrote:
> 

> That wouldn't be nice at all, it would totally
> change the
> way XSLT works. XSLT templates may be evaluated in
> any order,
> variable values may either be stored or
> re-calculated from the
> expression on each use, code may be re-arranged and
> optimised
> by the compiler. All of these things require that
> code is side effect
> free.
> 

Why would introducing a incrementable variable, change
*the way templates process presently* ? If I have a
variable at a xsl:stylesheet level say <xsl:variable2
name="a" select="0" />
and I use it in a xsl:template as below --
<xsl:template matche="something">
  <xsl:variable2 name="a" select="$a + 1" />
</xsl:template>

  This incrments variable *a* at a global place. I
agree that this template is producing side effect, but
does this model change the way templates are being
processed presently? variable *a* is being
incremented, its values can be used after this
statement, and the execution of rest of xsl:template
proceeds as usual.

  I can try to explain in another way -- For e.g. I
write something simple as <xsl:text></xsl:text> inside
<xsl:template .. Is  <xsl:variable2 name="a"
select="$a + 1" /> statement not similar to evaluation
of something like -- xsl:text ? 


> If you have a function f(x) and and expression
> 
> f(x) + f(x)
> 
> it may be optimised to 2 * f(x) which means you only
> have to calculate
> the function once.
> 
> However you can't do that if there is a possibility
> of the "function"
> doing something strange like incrementing teh value
> of some second
> variable y as in the first case y goes up by 2 and
> in the second it goes
> up by 1.
> 

I agree with you on this point that f(x) + f(x) can be
optimized to 2*f(x) if f(x) does'nt do any side effect
execution.. IMHO, are we not trying to justify the
functional nature of XSLT from a pure computer science
point of view.. But probably we have to accept this
functional nature of XSLT, as the optimizations
possible, and the processing model it facilitates far
outweigh little advantages some *side effect
producing* features may give..

> 
> Why use a functional language if you don't want to
> program in a
> functional style. There are plenty of non functional
> languages to choose
> from. 
> 
IMHO, I would ask -- what is the purpose of XSLT..? I
believe, to aid transformations of XML documents. That
is its sole objective.. Having it functional
definetely produce optimizations, side effect free
behaviour and other benifits which are required in
time critical -- real world applications.

I am agreeing by the majority opinion, that the
advantages of *functional programming* and *side
effect free* behaviour far outweigh the little
advatages some side effect producing features might
give(and probably cause to diminish the essence of
XSLT) ..

Regards,
Mukul

> David
> 
>
________________________________________________________________________
> This e-mail has been scanned for all viruses by Star
> Internet. The
> service is powered by MessageLabs. For more
> information on a proactive
> anti-virus service working around the clock, around
> the globe, visit:
> http://www.star.net.uk
>
________________________________________________________________________
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Current Thread
Keywords