5,693,062 members and growing! (18,412 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » General     Intermediate

Pagination using XSL

By VivekAyer

To display data in multiple pages using XSL.
XML, Windows, .NET, Visual Studio, ASP.NET, Dev

Posted: 10 Aug 2005
Updated: 16 Aug 2005
Views: 23,005
Bookmarked: 5 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
17 votes for this Article.
Popularity: 2.08 Rating: 1.69 out of 5
10 votes, 58.8%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 5.9%
4
6 votes, 35.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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>





License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

VivekAyer



Location: United Kingdom United Kingdom

Other popular .NET Framework articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
AnswerRE: Pagination using XSLmemberq2581:16 21 Nov '08  
QuestionNot understood properlymemberrascalpranesh23:53 23 Jun '08  
QuestionCannot go next page, the parameter Page and PageSize not changing on next pagememberPaillaRajashekarReddy2:18 13 May '08  
GeneralCannot go next page, the parameter Page and PageSize not changing on next pagememberEhteshamJax2:15 15 Aug '07  
Questionhow to use pagination to list the next records using next linkmemberchennaivijayan23:11 31 May '06  
AnswerRe: how to use pagination to list the next records using next linkmemberEhteshamJax2:17 15 Aug '07  
QuestionQuick questions.membereddiephoenix5:33 2 Feb '06  
GeneralDuh!memberDon Miguel0:40 11 Aug '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Aug 2005
Editor:
Copyright 2005 by VivekAyer
Everything else Copyright © CodeProject, 1999-2008
Web09 | Advertise on the Code Project