Profile User: node Name: victim of the information age Entry Tags Links Latest Month February 2012 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Search Search:

Category: Site & User FAQ Site Region Interest Username Email Gizmo/LJ Talk AIM ICQ Number Yahoo! ID MSN Jabber









<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <xsl:output method="html" indent="no" encoding="iso-8859-1" /> <!-- This template reads six parameters: previous: the value of "start" for the previous page perPage: number of entries per page next: the value of "start" for the next page total: total number of pages current: the page number we're currently on (we don't create a link to this) pageuri: uri to the current page (minus ?start=... params) The "start" info for previous/next points to the first record in the xml file to display for that page. If current is not 1 or total, we mark up both prev/next labels. We display ten entries at a time. If we have more than that, we display ellipses representing previous/next sets of entries. We do display "previous" link (links to current page - 1) if current page > 1 if pstart mod 10 = 0 pstart = pstart - 9 else pstart = current - (current mod 10) + 1 if current > 10 display ... link (links to pstart - 1) if total > (pstart + 9) pend = pstart + 9 display pstart to pend links (links to pages) display ... link (links to pend + 1) else pend = total display pstart to pend links (links to pages) display "next" link (links to current page + 1) if current page != total --> <xsl:template name="paging"> <xsl:param name="previous" /> <xsl:param name="perPage" /> <xsl:param name="next" /> <xsl:param name="current" /> <xsl:param name="total" /> <xsl:param name="pageuri" /> <xsl:variable name="pstart"> <xsl:choose> <xsl:when test="($current mod 10) = 0"> <xsl:value-of select="$current - 9" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$current - ($current mod 10) + 1" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- display previous link --> <xsl:if test="$current != 1"> <a href='{$pageuri}?start={$previous}&pgno={$current - 1}' class='gray'>Previous</a> </xsl:if> <xsl:if test="$current > 10"> <xsl:variable name="prevEllipsesPageNo" select="$pstart - 1" /> <xsl:variable name="prevEllipsesStart" select="1 + ($prevEllipsesPageNo - 1) * $perPage" /> <a href='{$pageuri}?start={$prevEllipsesStart}&pgno={$prevEllipsesPageNo}' class='gray'>...</a> </xsl:if> <xsl:choose> <xsl:when test="$total > ($pstart + 10)"> <xsl:variable name="pend" select="$pstart + 9" /> <xsl:call-template name="do-page"> <xsl:with-param name="perPage" select="$perPage" /> <xsl:with-param name="counter" select="$pstart" /> <xsl:with-param name="current" select="$current" /> <xsl:with-param name="total" select="$pend" /> <xsl:with-param name="pageuri" select="$pageuri" /> </xsl:call-template> <xsl:variable name="nextEllipsesPageNo" select="$pend + 1" /> <xsl:variable name="nextEllipsesStart" select="1 + ($nextEllipsesPageNo - 1) * $perPage" /> <a href='{$pageuri}?start={$nextEllipsesStart}&pgno={$nextEllipsesPageNo}' class='gray'>...</a> </xsl:when> <xsl:otherwise> <xsl:variable name="pend" select="$total" /> <xsl:call-template name="do-page"> <xsl:with-param name="perPage" select="$perPage" /> <xsl:with-param name="counter" select="$pstart" /> <xsl:with-param name="current" select="$current" /> <xsl:with-param name="total" select="$pend" /> <xsl:with-param name="pageuri" select="$pageuri" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> <!-- display next link --> <xsl:if test="$current != $total"> <a href='{$pageuri}?start={$next}&pgno={$current + 1}' class='gray'>Next</a> </xsl:if> </xsl:template> <xsl:template name="do-page"> <xsl:param name="perPage" /> <xsl:param name="counter" /> <xsl:param name="current" /> <xsl:param name="total" /> <xsl:param name="pageuri" /> <xsl:choose> <xsl:when test="$counter = $current"> <span style="color: white;"><strong><xsl:value-of select="$current" /></strong></span> </xsl:when> <xsl:otherwise> <a href='{$pageuri}?start={1 + ($counter - 1) * $perPage}&pgno={$counter}' class='gray'><xsl:value-of select="$counter" /></a> </xsl:otherwise> </xsl:choose> <xsl:if test="$counter < $total"> <xsl:call-template name="do-page"> <xsl:with-param name="perPage" select="$perPage" /> <xsl:with-param name="counter" select="$counter + 1" /> <xsl:with-param name="current" select="$current" /> <xsl:with-param name="total" select="$total" /> <xsl:with-param name="pageuri" select="$pageuri" /> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>

I needed pagination in XSL. Tags: geek, webdev write

permlink

Share

Flag