Solved

postion() is not working correctly in xsl

Posted on 2004-08-19
5
292 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
Comment Utility
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
Comment Utility
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
Comment Utility
doh, beat me to it ;o)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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