xsl-list
[Top] [All Lists]

Re: Re: Incrementing a Global variable

2003-08-27 18:44:03
Hi Dimitre,
  I am convinced that side effects are bad in a
programming language. Thanks for the links for
information about this topic. I believe the objective
of XSLT is to solve certain kind of problem(XML data
transformations). The problem of generating serial nos
comes frequently in real world situations. Would it
not be helpful(for transformations) if we can have a
construct which can increment variables(not full scale
-- but with limited features which can *aid* in
transformations)? Are we not justifying functional
nature of XSLT from a pure computer science view
point..

Regards,
Mukul

  

--- Dimitre Novatchev <dnovatchev(_at_)yahoo(_dot_)com> wrote:
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:


http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=uASG4eE2CHA.1560%40TK2MSFTNGP09&r

num=7&prev=/groups%3Fq%3Ddimitre%2Bxslt%2Bfunctions%2Bside%2Beffects%26hl%3D
en%26lr%3D%26ie%

3DUTF-8%26selm%3DuASG4eE2CHA.1560%2540TK2MSFTNGP09%26rnum%3D7
(read the whole thread)


http://groups.google.com/groups?hl=de&frame=right&th=418985883ecc2e2c&seekm=
uZk9iKYiBHA.2000%40tkmsftngp04#link1


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".

=====
Cheers,

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




"Mukul Gandhi" <mukulw3(_at_)yahoo(_dot_)com> wrote in message

news:20030827163907(_dot_)71895(_dot_)qmail(_at_)web41105(_dot_)mail(_dot_)yahoo(_dot_)com(_dot_)(_dot_)(_dot_)
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 ;)

Regards,
Mukul


--- Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com 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
http://sitebuilder.yahoo.com

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





 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