Skip to content

Instantly share code, notes, and snippets.

@bpierre
Created January 4, 2011 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpierre/765244 to your computer and use it in GitHub Desktop.
Save bpierre/765244 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<data>
<contributions>
<pagination
total-entries="11"
total-pages="2"
entries-per-page="10"
current-page="1" />
</contributions>
</data>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="data">
<!-- On déclare une variable qui pointe sur pagination, plus pratique -->
<xsl:variable name="pagination" select="/data/contributions/pagination" />
<!--
Si la page n’est pas la première, on affiche le lien « précédent »
Pour le numéro dans le lien, on fait @current-page-1
-->
<xsl:if test="$pagination/@current-page != 1">
<a href="http://example.com/{$pagination/@current-page-1}">Précédent</a>
<xsl:text> </xsl:text> <!-- Un espace dans un xsl:text, sinon il est ignoré -->
</xsl:if>
<!-- La page affichée, rien de compliqué ici -->
<span>
<xsl:text>Page </xsl:text>
<xsl:value-of select="$pagination/@current-page" />
<xsl:text>/</xsl:text>
<xsl:value-of select="$pagination/@total-pages" />
</span>
<!--
Si la page n’est pas la dernière, on affiche le lien « suivant »
Pour le numéro dans le lien, on fait @current-page+1
-->
<xsl:if test="$pagination/@current-page != $pagination/@total-pages">
<xsl:text> </xsl:text> <!-- Un espace dans un xsl:text, sinon il est ignoré -->
<a href="http://example.com/{$pagination/@current-page+1}">Suivant</a>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment