Click here to Skip to main content
Email Password   helpLost your password?

Introduction

Below is a way to display your xml in multiple pages with Prev and Next links. You could customize it to display any number of entries on a page. It takes in 2 parameters that could be passed as querystrings to the page.

Page - should hold the value of which page is currently displayed.
PageSize - should hold the value of how many entries should be displayed in a page.

 

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="3.2" encoding="ISO-8859-1"/> <xsl:param name="Page" select="0" /> <xsl:param name="PageSize" select="1" /> <xsl:template name="results" match="/">

<xsl:variable name="mycount" select="count(root/customer)"/> <xsl:variable name="selectedRowCount" select="round($mycount div $PageSize)"/>

<xsl:for-each select="root/customer"> <!-- Pagination logic --> <xsl:if test="position() &gt;= ($Page * $PageSize) + 1"> <xsl:if test="position() &lt;= $PageSize + ($PageSize * $Page)">

<!-- Do display here --> </xsl:if> </xsl:if> </xsl:for-each>

<!-- Prev link for pagination --> <xsl:choose> <xsl:when test="number($Page)-1 &gt;= 0">&#160; <A> <xsl:attribute name="href">_dirresult?page=<xsl:value-of select="number($Page)-1"/>&amp;pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> &lt;&lt;Prev </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose> <xsl:if test="$selectedRowCount &gt; 1"> &#160;<b class="blacktext"><xsl:value-of select="number($Page)+1"/>&#160;of&#160;<xsl:value-of select="number($selectedRowCount)"/></b>&#160; </xsl:if> <!-- Next link for pagination --> <xsl:choose> <xsl:when test="number($Page)+1 &lt; number($selectedRowCount)">&#160; <A> <xsl:attribute name="href">_dirresult?page=<xsl:value-of select="number($Page)+1"/>&amp;pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> Next&gt;&gt; </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose>

</xsl:template> </xsl:stylesheet>





You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
AnswerRE: Pagination using XSL
q258
1:16 21 Nov '08  
Probably a bit more efficient to just select what we want rather than select all then filter... Perhaps.... Thus a predicate in the for-each rather then consecutive nested if's...


<xsl:for-each
         select="root/customer[position() &gt;= (($Page * $PageSize) + 1)
         AND position() &lt;= ($PageSize + ($PageSize * $Page))">

<!-- Do display here -->

</xsl:for-each>
QuestionNot understood properly
rascalpranesh
23:53 23 Jun '08  
what is _dirresult?
This is servlet action? or any xml?
QuestionCannot go next page, the parameter Page and PageSize not changing on next page
PaillaRajashekarReddy
2:18 13 May '08  
hi,

i tried ur code its working. i have 15 records in my xml. in ur code
i give 5 for pagesize. it will dislay first 5 records i want to display next 5 records when i click the next>> link it will not display the next 5 records how to display the next 5 records and also if i click <<previous link it will display previous 5 records pls give the solution. i am waiting for ur reply.
AnswerRe: Cannot go next page, the parameter Page and PageSize not changing on next page
salahudeenDiamond
6:14 10 Mar '09  
Hi,

Have u got any solution for the problem. even i am facing similiar issue.. :(
GeneralCannot go next page, the parameter Page and PageSize not changing on next page
EhteshamJax
2:15 15 Aug '07  
i,

i tried ur code its working. i have 15 records in my xml. in ur code
i give 5 for pagesize. it will dislay first 5 records i want to display next 5 records when i click the next>> link it will not display the next 5 records how to display the next 5 records. i am waiting for ur reply.

Questionhow to use pagination to list the next records using next link
chennaivijayan
23:11 31 May '06  
hi,

i tried ur code its working. i have 15 records in my xml. in ur code i give 5 for pagesize. it will dislay first 5 records i want to display next 5 records when i click the next>> link it will not display the next 5 records how to display the next 5 records and also if i click <<previous link it will display previous 5 records pls give the solution. i am waiting for ur reply.

AnswerRe: how to use pagination to list the next records using next link
EhteshamJax
2:17 15 Aug '07  
Hello brother i am facing the same problem you asked. I need the solution.
GeneralRe: how to use pagination to list the next records using next link
salahudeenDiamond
6:15 10 Mar '09  
have u got any solution.. even i need it brother.
QuestionQuick questions.
eddiephoenix
5:33 2 Feb '06  
The reference "_dirresult" in the prev and next sections is to what?D'Oh!
Is it the xsl file, the xml file, asp page?


PHOENIX
GeneralDuh!
Don Miguel
0:40 11 Aug '05  
Quite good article!
No verbose explanations, no eyes-catching formating stuff,
just plain useful informations! Poke tongue


Last Updated 17 Aug 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010