xsl-list
[Top] [All Lists]

RE: Incrementing a Global variable

2003-08-27 11:30:02
I am not asking to introduce variables as like in
procedural languages.. We can keep xsl:variable as it
is, 

but can we introduce a syntax like xsl:variable2 (say
in XSLT 2.0 -- in addition to xsl:variable) which can
be defined at xsl:stylesheet level -- which can be
allowed to increment. The processing model of XSLT can
remain same(to maintain functional programming style);


the construct (e.g. xsl:variable2 ) can be maintained
in a global memory (maintained by XSLT processor) and
can be incremented..

for e.g. if I define <xsl:variable2 name="a"
select="0" />
 and possibly *any no of* other variables for e.g.
<xsl:variable2 name="b" .. etc. at xsl:stylesheet
level

and lets assume for e.g. -- this template is being
processed at some point..
<xsl:template matche="something">
  <xsl:variable2 name="a" select="$a + 1" />
</xsl:template>

When the processor encounters the statement --
<xsl:variable2 name="a" select="$a + 1" /> it will
increment the value of "a" at a global place..

Would introducing this feature will make XSLT really
procedural?

Thanks for your reference about <xsl:for-each
select="20 to 30"> ... but I could not see it on the
XSLT 2.0 site -- http://www.w3.org/TR/xslt20/

Regards,
Mukul


--- Michael Kay <mhk(_at_)mhk(_dot_)me(_dot_)uk> wrote:

Though the issue about incrementing the variables
has
been discussed a lot on this list, I feel if there
is
a feature where some sort of variable incrmenting
is
possible in XSLT, it will save lot of programming
hours producing a trivial thing as generating
serial
nos. I am not suggesting to deviate from the
viewpoint
that XSLT should be a functional language.

But it would deviate from that principle. It would
change it from a
functional language to a procedural one, in which
instructions have to
be executed in a fixed order.


Also if we can have looping constructs
which can iterate over number ranges for e.g.

for (int i=0; i < n; i++) , it will facilitate
processing loops in a diffrent way. 

XSLT 2.0 allows you to do this:

<xsl:for-each select="20 to 30">
  <xsl:value-of select="."/>
</xsl:for-each>

You can simulate this in 1.0 with

<xsl:for-each select="//node()[position() &lt;=
10]">
  <xsl:value-of select="position() + 20"/>
</xsl:for-each>

Michael Kay


 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