From: <bi...@us...> - 2009-03-03 20:34:43
|
Revision: 2688 http://archive-access.svn.sourceforge.net/archive-access/?rev=2688&view=rev Author: binzino Date: 2009-03-03 20:34:38 +0000 (Tue, 03 Mar 2009) Log Message: ----------- Re-worked the page link generation to handle last-page and paging-off-the-end. Modified Paths: -------------- trunk/archive-access/projects/nutchwax/archive/src/nutch/src/web/jsp/search.xsl Modified: trunk/archive-access/projects/nutchwax/archive/src/nutch/src/web/jsp/search.xsl =================================================================== --- trunk/archive-access/projects/nutchwax/archive/src/nutch/src/web/jsp/search.xsl 2009-03-03 18:20:14 UTC (rev 2687) +++ trunk/archive-access/projects/nutchwax/archive/src/nutch/src/web/jsp/search.xsl 2009-03-03 20:34:38 UTC (rev 2688) @@ -192,37 +192,73 @@ <xsl:template name="pageLinks"> <xsl:param name="labelPrevious" /> <xsl:param name="labelNext" /> + <xsl:variable name="startPage" select="floor(opensearch:startIndex div opensearch:itemsPerPage) + 1" /> + <xsl:variable name="lastPage" select="floor(opensearch:totalResults div opensearch:itemsPerPage) + 1" /> <!-- If we are on any page past the first, emit a "previous" link --> - <xsl:if test="(floor(opensearch:startIndex div opensearch:itemsPerPage) + 1) != 1"> + <xsl:if test="$startPage != 1"> <xsl:call-template name="pageLink"> - <xsl:with-param name="pageNum" select="floor(opensearch:startIndex div opensearch:itemsPerPage)" /> + <xsl:with-param name="pageNum" select="$startPage - 1" /> <xsl:with-param name="linkText" select="$labelPrevious" /> </xsl:call-template> <xsl:text> </xsl:text> </xsl:if> <!-- Now, emit numbered page links --> <xsl:choose> - <xsl:when test="(floor(opensearch:startIndex div opensearch:itemsPerPage) + 1) < 11"> - <xsl:call-template name="numberedPageLinks" > - <xsl:with-param name="begin" select="1" /> - <xsl:with-param name="end" select="21" /> - <xsl:with-param name="current" select="floor(opensearch:startIndex div opensearch:itemsPerPage) + 1" /> - </xsl:call-template> + <!-- We are on pages 1-10. Emit links --> + <xsl:when test="$startPage < 11"> + <xsl:choose> + <xsl:when test="$lastPage < 21"> + <xsl:call-template name="numberedPageLinks" > + <xsl:with-param name="begin" select="1" /> + <xsl:with-param name="end" select="$lastPage + 1" /> + <xsl:with-param name="current" select="$startPage" /> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="numberedPageLinks" > + <xsl:with-param name="begin" select="1" /> + <xsl:with-param name="end" select="21" /> + <xsl:with-param name="current" select="$startPage" /> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> </xsl:when> + <!-- We are past page 10, but not to the last page yet. Emit links for 10 pages before and 10 pages after --> + <xsl:when test="$startPage < $lastPage"> + <xsl:choose> + <xsl:when test="$lastPage < ($startPage + 11)"> + <xsl:call-template name="numberedPageLinks" > + <xsl:with-param name="begin" select="$startPage - 10" /> + <xsl:with-param name="end" select="$lastPage + 1" /> + <xsl:with-param name="current" select="$startPage" /> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="numberedPageLinks" > + <xsl:with-param name="begin" select="$startPage - 10" /> + <xsl:with-param name="end" select="$startPage + 11" /> + <xsl:with-param name="current" select="$startPage" /> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <!-- This covers the case where we are on (or past) the last page --> <xsl:otherwise> <xsl:call-template name="numberedPageLinks" > - <xsl:with-param name="begin" select="floor(opensearch:startIndex div opensearch:itemsPerPage) + 1 - 10" /> - <xsl:with-param name="end" select="floor(opensearch:startIndex div opensearch:itemsPerPage) + 1 + 11" /> - <xsl:with-param name="current" select="floor(opensearch:startIndex div opensearch:itemsPerPage) + 1" /> + <xsl:with-param name="begin" select="$startPage - 10" /> + <xsl:with-param name="end" select="$lastPage + 1" /> + <xsl:with-param name="current" select="$startPage" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> <!-- Lastly, emit a "next" link. --> <xsl:text> </xsl:text> - <xsl:call-template name="pageLink"> - <xsl:with-param name="pageNum" select="floor(opensearch:startIndex div opensearch:itemsPerPage) + 2" /> - <xsl:with-param name="linkText" select="$labelNext" /> - </xsl:call-template> + <xsl:if test="$startPage < $lastPage"> + <xsl:call-template name="pageLink"> + <xsl:with-param name="pageNum" select="$startPage + 1" /> + <xsl:with-param name="linkText" select="$labelNext" /> + </xsl:call-template> + </xsl:if> </xsl:template> <!-- Template to emit a list of numbered links to results pages. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |