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: