xsl-list
[Top] [All Lists]

Re: Incrementing a Global variable

2003-08-26 21:59:40
Hi! Mukul

Perhaps nobody understood my problem

XSL/XPath have failed to do a trivial thing!!

Here are some more detail...

This is an database(Oracle9i)
generated complex xml, which is validated by some
standard schemas.Which I am transforming to XSL:FO
using XSLT to get a PDF output.

It would be not possible to post 4000 lines complete
xslt code. I've formulated sample files to illustrate
the problem(now I've made it a pure XSL problem and
not a FO problem, but FO Solution is also welcome ):
************************************************

Input XML file:(sample.xml)
---------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Students>
      <Student>
            <Name>SAM</Name>
            <TOption>English </TOption>
      </Student>
      <Student>
            <Name>RAJ</Name>
            <TOption>English </TOption>
      </Student>
      <Student>
            <Name>RON</Name>
            <TOption>English </TOption>
      </Student>
      <Student>
            <Name>JON</Name>
            <TOption>German  </TOption>
      </Student>
      <Student>
            <Name>DON</Name>
            <TOption>German  </TOption>
      </Student>
      <Student>
            <Name>MON</Name>
            <TOption>Hebrew  </TOption>
      </Student>
      <Student>
            <Name>GON</Name>
            <TOption>Hebrew  </TOption>
      </Student>
</Students>
**********************************************

PDF/HTML Output:( I'm Getting)
--------------------------
|1 |SAM        |English  |
|--|-----------|---------|
|2 |RAJ        |English  |
|--|-----------|---------|
|3 |RON        |English  |
|--|-----------|---------|
|4 |           |         |
|--|-----------|---------|
|4 |JON        |German   |
|--|-----------|---------|
|5 |DON        |German   |
|--|-----------|---------|
|6 |           |         |
|--|-----------|---------|
|6 |MON        |Hebrew   |
|--|-----------|---------|
|7 |GON        |Hebrew   |
|--|-----------|---------|
|10| Total = 7 |         |
|--|-----------|---------|
|11|           |         |
|--|-----------|---------|
|12|           |         |
|--|-----------|---------| 
|13|           |         |
|--|-----------|---------|
|14|           |         |
|--|-----------|---------|
|15|           |         |
--------------------------
***********************************************

PDF/HTML Output:( I Require)
--------------------------
|1 |SAM        |English  |
|--|-----------|---------|
|2 |RAJ        |English  |
|--|-----------|---------|
|3 |RON        |English  |
|--|-----------|---------|
|4 |           |         |
|--|-----------|---------|
|5 |JON        |German   |
|--|-----------|---------|
|6 |DON        |German   |
|--|-----------|---------|
|7 |           |         |
|--|-----------|---------|
|8 |MON        |Hebrew   |
|--|-----------|---------|
|9 |GON        |Hebrew   |
|--|-----------|---------|
|10| Total = 7 |         |
|--|-----------|---------|
|11|           |         |
|--|-----------|---------|
|12|           |         |
|--|-----------|---------| 
|13|           |         |
|--|-----------|---------|
|14|           |         |
|--|-----------|---------|
|15|           |         |
--------------------------****************************************

XSLT File: (sample.xslt)
------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
      <xsl:output method="html" version="1.0"
encoding="UTF-8" indent="yes"/>
      <xsl:variable name="varRowLimit" select="15"/>
      <xsl:template match="Students">
            <xsl:variable name="Student_Count"
select="count(Student)"/>
            <xsl:variable name="BreakCount"
select="count(Student[not(TOption =
following-sibling::*/TOption)])"/>
            <html>
                  <table >
                        <xsl:for-each
select="Student">
                              <tr>
                                    <td>
                                          <xsl:choose>
                                               
<xsl:when test="position() mod
$varRowLimit=0">
                                                     
<xsl:value-of select="$varRowLimit "/>
                                               
</xsl:when>
                                               
<xsl:otherwise>
                                                     
<xsl:value-of select="(position()  mod
$varRowLimit)"/>
                                               
</xsl:otherwise>
                                         
</xsl:choose>
                                    </td>
                                    <td>
                                         
<xsl:value-of select="Name"/>
                                    </td>
                                    <td>
                                         
<xsl:value-of select="TOption"/>
                                    </td>
                              </tr>
                              <xsl:variable
name="CurrTOption"
select="TOption"/>
                              <xsl:variable
name="NextTOption"
select="following-sibling::*/TOption"/>
                              <xsl:if
test="not(position()=last())">
                                    <xsl:if
test="not($NextTOption=$CurrTOption)">
                                         
<xsl:call-template name="PrintBlankRows">
                                               
<xsl:with-param name="start_count"
select="position()+1"/>
                                               
<xsl:with-param name="no_of_BlankRows"
select="position()+2"/>
                                         
</xsl:call-template>
                                    </xsl:if>
                              </xsl:if>
                              <xsl:if
test="position()=last()">
                                    <tr>
                                          <td>
                                               
<xsl:value-of select="($Student_Count
+$BreakCount ) mod  $varRowLimit "/>
                                          </td>
                                          <td>
                                                Total
=      <xsl:value-of select="$Student_Count
"/>
                                          </td>
                                          <td>
                                               
<xsl:text
disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
                        
                                          </td>
                                    </tr>
                                    <xsl:variable
name="no_of_BlankLines">
                                         
<xsl:call-template name="RowsRemaining">
                                               
<xsl:with-param name="ncount"
select="$Student_Count"/>
                                         
</xsl:call-template>
                                    </xsl:variable>
                                    <xsl:call-template
name="PrintBlankRows">
                                         
<xsl:with-param name="start_count"
select="($Student_Count +$BreakCount + 1) mod 
$varRowLimit "/>
                                         
<xsl:with-param name="no_of_BlankRows"
select="(($Student_Count +$BreakCount +1) mod 
$varRowLimit ) + ($no_of_BlankLines - $BreakCount) "/>
                                   
</xsl:call-template>
                              </xsl:if>
                        </xsl:for-each>
                  </table>
            </html>
      </xsl:template>
      <xsl:template name="PrintBlankRows">
            <xsl:param name="start_count"/>
            <xsl:param name="no_of_BlankRows"/>
            <xsl:if test="$start_count &lt;
$no_of_BlankRows">
                  <tr>
                        <td>
                              <xsl:value-of
select="$start_count"/>
                        </td>
                        <td>
                              <xsl:text
disable-output-escaping="yes"><![CDATA[
]]></xsl:text>
                        </td>
                        <td>
                              <xsl:text
disable-output-escaping="yes"><![CDATA[
]]></xsl:text>      
                                                </td>
                  </tr>
                  <xsl:call-template
name="PrintBlankRows">
                        <xsl:with-param
name="start_count"
select="$start_count + 1"/>
                        <xsl:with-param
name="no_of_BlankRows"
select="$no_of_BlankRows"/>
                  </xsl:call-template>
            </xsl:if>
      </xsl:template>
      <xsl:template name="RowsRemaining">
            <xsl:param name="ncount"/>
            <xsl:choose>
                  <xsl:when test="$ncount &lt;=
$varRowLimit">
                        <xsl:value-of
select="$varRowLimit - $ncount "/>
                  </xsl:when>
                  <xsl:otherwise>
                        <xsl:call-template
name="RowsRemaining">
                              <xsl:with-param
name="ncount" select="$ncount -
$varRowLimit"/>
                        </xsl:call-template>
                  </xsl:otherwise>
            </xsl:choose>
      </xsl:template>
</xsl:stylesheet>
****************************************************


for simplicity I've removed FO Tags
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)


Thanks & Regards,
Raj


--- Mukul Gandhi <mukulw3(_at_)yahoo(_dot_)com> wrote:
Hi Raj,
  I uderstand from your problem description that you
have <student> tags and you want to generate running
serial numbers (Sl No). You want to print one blank
line after printing some number of lines *having
text*(the <student> tags).

e.g. you are producing blank like after -

3 | RON | English

after, 6 | DON | German and so on.

From your problem description it is not clear, *how
you decide* after which record you are printing
blank
line. After last printable line, you wish to print
blank rows with serial nos till some fixed count.

position() and count() functions are commonly used
to
generate serial nos..

I feel you should give more details about the
problem.. 

Regards,
Mukul


--- Rajendra S Rawat <rajsrawat(_at_)yahoo(_dot_)com> wrote:
This drawback of XSL/XSL:FO is quite frustating



I want something like this 
--------------------------------------
|Sl No | STUDENT NAME     | TOption   |
--------------------------------------
| 1    |  SAM             |  English  | <-
position()=1
--------------------------------------
| 2    |  RAJ             |  English  | <-
position()=2
--------------------------------------
| 3    |  RON             |  English  | <-
position()=3
--------------------------------------
| 4    |                  |           |
--------------------------------------
| 5    |  JON             |  German   | <-
position()=4
--------------------------------------
| 6    |  DON             |  German   | <-
position()=5
--------------------------------------
| 7    |                  |           |
-------------------------------------- 
| 8    |  MON             |  Hebrew   | <-
position()=6
--------------------------------------
| 9    |  GON             |  Hebrew   | <-
position()=7
--------------------------------------
| 10   | TOTAL= 7         |           |
--------------------------------------
| 11   |                  |           |
--------------------------------------
| 12   |                  |           |
--------------------------------------
| 13   |                  |           |
-------------------------------------- 
| 14   |                  |           |
--------------------------------------
| 15   |                  |           |
---------------------------------------

Pl. Note 
1. the rows with out values
2. position() is not same as Sl No.
3. blank rows continues till end of page
4. after first break diff between position() and
Sl
No. is 1 (then after second break 2 ....)
5. this is only a very tiny part of xml/output
used
to
just illustrate the problem, So I cannot use
static
sl. no. (it is in a <xsl:for-each select="Student"
..loop)


I have however created above table (breaks by
grouping
and extra blank-rows by recursion)

but could not get Sl. No. ordered
I can get something like
--------------------------------------
|Sl No | STUDENT NAME     | TOption   |
--------------------------------------
| 1    |  SAM             |  English  | <-
position()=1
--------------------------------------
| 2    |  RAJ             |  English  | <-
position()=2
--------------------------------------
| 3    |  RON             |  English  | <-
position()=3
--------------------------------------
|      |                  |           |
--------------------------------------
| 4    |  JON             |  German   | <-
position()=4
--------------------------------------
| 5    |  DON             |  German   | <-
position()=5
--------------------------------------
|      |                  |           |
--------------------------------------
| 6    |  MON             |  Hebrew   |<-
position()=6
--------------------------------------
| 7    |  GON             |  Hebrew   |<-
position()=7
--------------------------------------
| 10   | TOTAL= 7         |           |
--------------------------------------
| 11   |                  |           |
--------------------------------------
| 12   |                  |           |
--------------------------------------
| 13   |                  |           |
-------------------------------------- 
| 14   |                  |           |
--------------------------------------
| 15   |                  |           |
--------------------------------------


I got last sl no.(10-15) ordered by using 
1. break-count(here 2) 
2. Student nodes count(here 7) 
3. total no. of rows (here 15)(fixed)

Actual Problem is to print Sl No.(Here 1 to 9)

Only solution I suppose, is adding 1,2... after
1st,2nd... breaks but for that I require a global
variable which I can increment and add after every
break.........BUT....in XSL  variables are read
only!!!!!!!


can anybody show me a way? 

(Pl. Also Note Final out put is in PDF.Can it be
achieved with FO .....with backgroud image or
Absolute
Positioning...

for this problem I also tried ft:assign but failed
to
use it

Has any body used ft:assign? )




tia

Regards,
Raj

__________________________________
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



__________________________________
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



__________________________________
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



<Prev in Thread] Current Thread [Next in Thread>