Solved

postion() is not working correctly in xsl

Posted on 2004-08-19
5
294 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
To fetch data from XML with multiple root nodes 6 73
Change to event 1 111
Fixing Non-Standard characters in text 8 103
XML XSL Message 3 21
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

13 Experts available now in Live!

Get 1:1 Help Now