Solved

postion() is not working correctly in xsl

Posted on 2004-08-19
5
293 Views
Last Modified: 2012-05-05
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:param name="recordsPerPage" select="10" />
<xsl:param name="pageNumber" select="page/request/parameters/pageNumber" />
<xsl:template match="page">
<HTML>
<HEAD>
<TITLE> XSLT In Java </TITLE>
<link rel="stylesheet" href="html/eSupplyTableSortCSS.css"/>

</HEAD>
<BODY class='formdata'>
<form method="post">
records:<xsl:value-of select="$recordCount" />      
pageNumber:<xsl:value-of select="$pageNumber" />
      <table cellSpacing='0' cellpadding='0'  border="1" width='95%'>
      <center>
            <tr CLASS='formheader'>
            <td><u>C</u>onsol No</td>
            <td><u>M</u>AWB No</td>
            <td><u>O</u>rigin</td>
            <td><u>D</u>estination</td>
            <td><u>A</u>irline</td>
            <td><u>F</u>light</td>
            <td><u>E</u>TD</td>
            <td>E<u>T</u>A</td>
            <td>C<u>u</u>t Off Date</td>
            </tr>
            <xsl:for-each select="ROWSET/ROW">
            <!--this performs the output in table format - and shows
only that many records passed in the recordcount parameter -->

<xsl:if test="position() &gt;  $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) +
            $recordsPerPage)">
            <!-- Each record on a seperate row -->
            position:::<xsl:value-of select="position()" />
            <tr  class='formdata'>
            <td>
                  <xsl:value-of select="CONSOLEID" />
            </td>

            <td>
                  <xsl:value-of select="MASTERDOCID" />
            </td>

            <td>
                  <xsl:value-of select="ORIGIN" />
            </td>

            <td>
                  <xsl:value-of select="DESTINATION" />
            </td>

            <td>
                  <xsl:value-of select="CARRIERID" />
            </td>

            <td>
                  <xsl:value-of select="FLIGHT_NO" />
            </td>
            <td>
                  <xsl:value-of select="ETD" />
            </td>
            <td>
                  <xsl:value-of select="ETA" />
            </td>
            <td>
                  <xsl:value-of select="CUTOFF_DATE" />
            </td>
            </tr>
      </xsl:if>
      </xsl:for-each>
</table>
<table cellSpacing='0' cellpadding='0'  border="1" width='95%'>
<tr class='formdata'>
<td width="10%">
            <xsl:if test="$pageNumber > 0">
                  <xsl:element name="a">
<xsl:attribute name="href">?pagenumber=<xsl:value-of select="number($pageNumber)-1" />&amp;previous=Previous</xsl:attribute>
                         Previous
                  </xsl:element>                    
            </xsl:if>
</td>
<td width="85%">
            <!-- Next page, do not show when at end() of listing -->
            <xsl:if test="($recordCount - ((1+number($pageNumber)) *
$recordsPerPage))> 0">
                  <xsl:element name="a">
            <xsl:attribute name="href">emp.jsp?pagenumber=<xsl:value-of select="number($pageNumber)+1" />&amp;next=Next</xsl:attribute>
                               Next
                  </xsl:element>
            </xsl:if>
            <!-- End Of Show previous/next page links-->
      </td>
      </tr>
      </table>
      </form>
            </BODY>
            </HTML>
      </xsl:template>
</xsl:stylesheet>

above is xsl paging code  

look at this condition
in this condition initially pageNumber=0;

<xsl:if test="position() &gt;  $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) +
            $recordsPerPage)">

            first time it is displaying 10 records and i am displaying positions <xsl:value-of select="position()" />
            it is coming correctly 1-10

            when i click next button it is coming 11-20

            above condition working perfectly

when i changed the condition like this
in this condition initially pageNumber=1;
<xsl:if test="position() &lt;= number($recordsPerPage) * number($pageNumber)">

first time it is displaying 1-10 records

when i click next button it is coming  1-20 records but it should come 11-20 why ithe position has come to 1st again;

where went wrong

0
Comment
Question by:chaitu chaitu
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
ramazanyich earned 250 total points
ID: 11840328
shouldn't it be
<xsl:if test="position() &lt;= number($recordsPerPage) * number($pageNumber) and position() &gt; number($recordsPerPage) * number($pageNumber - 1)">
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 11840482
Try changing your test to:

<xsl:if test="position() &lt;= number($recordsPerPage) * number($pageNumber) and position() &gt; number($recordsPerPage) * (number($pageNumber)-1)">
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11840485
doh, beat me to it ;o)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now