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”


    <<previous

Handling weither to display “» next”


  next >>

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


     ...

     ...

Questions or comments?

Join the discussion on Discord, ask a question or share your experience.

Discuss on Discord
  1. Arduino smart power controller on a 1U rack shelfArduino driven 5v and 12v Smartpower
  2. Javascript: Decode HTML entities