lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Whitman <>
Subject Re: Pagination of results and XSLT.
Date Tue, 24 Jul 2007 01:27:18 GMT
> Has anyone tried to handle pagination of results using XSLT's ? I'm  
> not really sure it is possible to do it in pure XSLT because all  
> the response object gives us is a total document count - paginating  
> the results would involve more than what XSLT 1.0 could handle  
> (I'll be very happy if someone proves me wrong :)).

We do pagination in XSL 1.0 often -- direct from a solr response  
right to HTML/CSS/JS.
You get both the start and total rows from the solr response, so I  
don't know what else you'd need.

Here's a snip of a paging XSL in solr. The referred JS function  
pageResults just sets the &start= solr param.

<xsl:variable name="numFound" select="response/result/@numFound"/>
<xsl:variable name="start" select="response/result/@start"/>	
<xsl:variable name="pages" select="floor($numFound div 10)"/>
<xsl:variable name="page" select="floor($start div 10)+1"/>

	<xsl:when test="$pages &gt; 1">
		<div class="pagination">		
				<xsl:call-template name="loopPages">
					<xsl:with-param name="goUntil" select="$pages"/>
					<xsl:with-param name="currentPage" select="$page"/>					
					<xsl:with-param name="startAt" select="1"/>

<xsl:template name="loopPages">
	<xsl:param name="startAt">0</xsl:param>
	<xsl:param name="goUntil">0</xsl:param>
	<xsl:param name="currentPage">0</xsl:param>
	<xsl:if test="number($startAt) &lt; number($goUntil)+1">
			<xsl:when test="number($startAt) = number($currentPage)">
					<a class="currentpage" href="#" onClick="pageResults 
('{$startAt}');"><xsl:value-of select="$startAt"/></a>
					<a href="#" onClick="pageResults('{$startAt}');"><xsl:value-of  
		<xsl:call-template name="loopPages">
			<xsl:with-param name="startAt" select="$startAt + 1"/>
			<xsl:with-param name="goUntil" select="$goUntil"/>
			<xsl:with-param name="currentPage" select="$currentPage"/>

View raw message