Subject: [xsl] Re: Incrementing a Global variable From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Wed, 27 Aug 2003 21:47:17 +0200 |
> 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@xxxxxxxxx> wrote in message news:20030827163907.71895.qmail@xxxxxxxxxxxxxxxxxxxxxxxxxx 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.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 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Incrementing a Global var, David Carlisle | Thread | Re: [xsl] Re: Incrementing a Global, Mukul Gandhi |
RE: [xsl] Question about Page-Maste, Lehming, Thea | Date | [xsl] Re: Incrementing a Global var, Dimitre Novatchev |
Month |