XSLT: Make a smart pagination in HTML

Use XSLT to make a smart pagination rendering result in HTML, more or less like the google one. The following is extracted from an old project of my own and the code is not expected to works as is. It took every needed parts, but as this code is out of its original context, it probably needs some work. Nevertheless, it can be a begining.

Description

The purpose is to show N pages with “…” at the end for the first time results are displayed. Then, if you click on the last shown page, you will see N pages before and N pages after the one you clicked. for example: if you have:

1 – 2 – 3 – 4 – 5 … next >>

clicking on “5” will display

<< previous 1 – 2 – 3 – 4 – 5 – 6 – 7 – 8 – 9 – 10 … next >>/>

then clicking on 10 will display

<< previous … 6 – 7 – 8 – 9 – 10 – 11 – 12 – 13 – 14 – 15 … next >>

XSLT code

Handling weither to display “<< previous”

Handling weither to display “>> next”

Between previous and next link: show page numbers

just place a call to the following template (eg. <xsl:call-template name=”num_page”/>)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.