Re: [xsl] Incrementing a Global variable

Subject: Re: [xsl] Incrementing a Global variable
From: Bill Keese <billk@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 28 Aug 2003 10:35:18 +0900
Can't you use <xsl:number> to get what you want? Maybe I didn't understand something about the problem you were solving.

Bill

Mukul Gandhi wrote:

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