[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Incrementing a Global variable

Subject: Re: Incrementing a Global variable
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 27 Aug 2003 21:47:17 +0200
xslt counter variable
> But if lets say we are allowed to declare a global
> variable and can increment it, it will make certain
> tasks quite easy(like generating serial nos).

Global variables (e.g. static memory) is not considered to be a good
programming practice even with imperative OOP languages.

Uncontrolled side effects are really harmful (and not only when using a
functional language: e.g. see
http://www.wikipedia.org/wiki/Side-effect_(computer_science) ) and there are
xslt programmers, who have suffered in their real work, because they were
not aware of this.

See for example:

(read the whole thread)


Anyone, who cannot get accustomed to the best feature of XSLT (its being a
functional language without side effects) will be far better off if they
stop torturing themselves with XSLT. XSLT requires a change in the way one
thinks -- if this change does not happen or takes too-long then we witness
requests for such "features".


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Mukul Gandhi" <mukulw3@xxxxxxxxx> wrote in message
The XSLs (by Jarno and by -- Americo) are brilliant..
I was trying to solve the problem, but could'nt come
up with the solution soon..

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 if lets say we are allowed to declare a global
variable and can increment it, it will make certain
tasks quite easy(like generating serial nos). Since
generating serial nos is a common requirement, IMHO
providing this capability in XSLT will help the user
community. 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. Presently for-each
loop iterate over *node sets*. I guess these things
might be added to XSLT without deviating from the
objective to keep XSLT as a functional language.

The XSLT 2.0 spec is in draft stage. If appropriate,
these features can be thought to be added. Probably
more knowledgeable persons on this list -- M. Kay,
Dimitre, David Carlisle, Dave Pawson, Wendell, Jeni,
Jarno, Americo.. can comment on the appropriateness of
this idea ;)


--- Jarno.Elovirta@xxxxxxxxx wrote:
> Hi,
> > Also i have Isolated Problem Page from  Actual
> output
> > which contains multiple pdf pages. This part is
> > conditionaly separated from other pdf pages (
> which
> > are
> > further grouped using Muenchian Method)
> Could you integrage this approach to your
> stylesheets?
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:output method="html"/>
>   <xsl:variable name="varRowLimit" select="15"/>
>   <xsl:variable name="Student_Count"
> select="count(Students/Student)"/>
>   <xsl:template match="Students">
>     <title></title>
>     <table>
>       <tbody>
>         <xsl:apply-templates select="Student[1]"/>
>       </tbody>
>     </table>
>   </xsl:template>
>   <xsl:template match="Student" name="Student">
>     <xsl:param name="counter" select="1"/>
>     <tr>
>       <td>
>         <xsl:value-of select="$counter"/>
>       </td>
>       <td>
>         <xsl:value-of select="Name"/>
>       </td>
>       <td>
>         <xsl:value-of select="TOption"/>
>       </td>
>     </tr>
>     <xsl:variable name="next"
> select="following-sibling::Student[1]"/>
>     <xsl:choose>
>       <xsl:when test="not($next)">
>         <tr>
>           <td>
>             <xsl:value-of select="$counter + 1"/>
>           </td>
>           <td>
>             <xsl:text/>Total = <xsl:value-of
> select="$Student_Count"/>
>           </td>
>           <td></td>
>         </tr>
>         <xsl:call-template name="empty">
>           <xsl:with-param name="counter"
> select="$counter + 2"/>
>           <xsl:with-param name="left"
> select="$varRowLimit - $Student_Count - 3"/>
>         </xsl:call-template>
>       </xsl:when>
>       <xsl:when test="TOption = $next/TOption">
>         <xsl:apply-templates select="$next">
>           <xsl:with-param name="counter"
> select="$counter + 1"/>
>         </xsl:apply-templates>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:call-template name="empty">
>           <xsl:with-param name="counter"
> select="$counter + 1"/>
>         </xsl:call-template>
>         <xsl:apply-templates select="$next">
>           <xsl:with-param name="counter"
> select="$counter + 2"/>
>         </xsl:apply-templates>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
>   <xsl:template name="empty">
>     <xsl:param name="counter" select="0"/>
>     <xsl:param name="left" select="1"/>
>     <xsl:if test="$left">
>       <tr>
>         <td>
>           <xsl:value-of select="$counter"/>
>         </td>
>         <td></td>
>         <td></td>
>       </tr>
>       <xsl:call-template name="empty">
>         <xsl:with-param name="counter"
> select="$counter + 1"/>
>         <xsl:with-param name="left" select="$left -
> 1"/>
>       </xsl:call-template>
>     </xsl:if>
>   </xsl:template>
> </xsl:stylesheet>
> Cheers,
> Jarno - Feindflug: Größenwahn (Life Cried Remix)
>  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

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

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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.