ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Result Pagination with XSL
Submitter: Not specified Not specified (other recipes)
Last Updated: 2002/03/21
Version no: 1.0
Category: Miscellaneous

 

4 stars 1 vote(s)


Description:

My technique for separating Xml results into pages. The great thing is that it is fully implemented in XSL, the bad thing is that you still have to deal with the entire result, even though you are only showing a portion of it.

Source: Text Source

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no" />

<!-- Define these two parameters. Increment or decrement 
     the "Page" Parameter by one to scroll through the results. Zero is
     the first page. The "PageSize" parameter controls the number
     of results per page. -->
<xsl:param name="Page" select="0" />
<xsl:param name="PageSize" select="5" />

<!-- This example uses a top-level message list from a discussion board. -->
<xsl:template match="/">
	<xsl:for-each select="/TopicList/Topic">
		<!-- Check to see if we have reached the start position yet -->
		<xsl:if test="position() >= ($Page * $PageSize) + 1">
			<!-- Check to see if we have returned the right
			     number of results yet. -->
			<xsl:if test="position() <= $PageSize + ($PageSize * $Page)">
				<!-- Do Some Work -->
			</xsl:if>
		</xsl:if>
	</xsl:for-each>
</xsl:template>

The license for this recipe is available here.

Discussion:

It's easy to know when to display "previous" and "next" links. Tell me what you think.



Add comment

Number of comments: 5

Hey, what the..?, Not specified Not specified, 2002/03/21
I didn't get any credit. Probably because i used Passport sign in. This was submitted by:

Brandon Croft
brandon@gobigfishgo.com
www.gobigfishgo.com

Add comment

next links question for pagination, Zoe Peng, 2002/05/10
Hi, I got a question here. Please help.. If /TopicList/Topic has over 5 records(let's say 7 records), I am going to divide it by two pages with next links. (Page1: have 5 records and next link to Page 2) When I click the next links, it will return the whole /TopicList/Topic again and try to use the same stylesheet to do the transform again. The question is: when I implement the links, the Page1 is good that return five records and next link. But, after I click the link again, it returns the whole seven records for me. Any ideas? Thanks. --Zoe mpeng@atxtelematics.com
Add comment

Next and Previous links?!?!, Rob MacDonald, 2003/01/20
How do you display the next and previous links?!?!?
Add comment

Prev, Next links....., nba scrub, 2003/06/04
So how would you determine when to display prev and next links and making sure the last page doesn't contain a next link ?
Add comment

how to enable caching in apache cocoon, Bhavya Sharma, 2006/09/05
hi Devs Could u give me any idea that how can we enable caching Thanks Bhavya
Add comment



Highest rated recipes:

1. Search and Replace

2. Generating a newline

3. Internationalization ...

4. Result Pagination with ...

5. Restricting processing ...

6. Fetching information ...

7. Getting text children of ...

8. Creating empty elements




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.