Re: Another variable question

Subject: Re: Another variable question
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 03 Jun 1999 13:47:43 -0400
At 99/06/03 17:54 +0100, Christian NENTWICH wrote:
>a little newbie question that can be answered quickly. 

Quickly, yes, but perhaps not to your satisfaction.

>Suppose a have a global variable like this:
>
>   <xsl:variable name="current_x">20</xsl:variable>
>
>I want to use that variable to keep track of coordinates.. every time I
>encounter a certain element, I want to increase it 

The value 20 is bound to the variable in global scope named "current_x" and
*cannot* be changed.

Because of the side-effect free nature of XSL, a bound variable cannot have
its value changed.

>(I cannot use counters
>for this purpose because I  will have to do other operations in the future),

You will need to recalculate the changing value you need, based on your
changing position in the source node tree, each time you need a new value.

When I first learned about side-effect-free programming, I was trying to
keep a global counter of a chapter number in a book, incrementing at the
start of each chapter (since I learned only the traditional programming
style of global variables).  That was when I learned that I needed to
calculate the number of the chapter from the input structure each time I
needed the chapter number in a different scope (if I needed the calculated
many times within a given scope, I would bind the value to a variable in
that scope and use it as many times as I needed).

There was a discussion in the past (that I'm not trying to revive right
now!) about the fact that variables do not vary, and that the name of the
construct could be construed from the mathematical sense of a place-holder.

I hope this helps.

.......... Ken


--
G. Ken Holman                  mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.           http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999  (Fax:-0995)
Website: XSL/XML/DSSSL/SGML services outline,  XSL/DSSSL shareware,
         stylesheet resource library, conference training schedule,
         commercial stylesheet training materials, on-line XSL CBT.


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


Current Thread