lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Whitman <brian.whit...@variogr.am>
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:choose>
	<xsl:when test="$pages &gt; 1">
		<div class="pagination">		
			<ul>
				<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:call-template>
			</ul>
		</div>
	</xsl:when>
</xsl:choose>
		

<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:choose>
			<xsl:when test="number($startAt) = number($currentPage)">
				<li>
					<a class="currentpage" href="#" onClick="pageResults 
('{$startAt}');"><xsl:value-of select="$startAt"/></a>
				</li>
			</xsl:when>
			<xsl:otherwise>
				<li>
					<a href="#" onClick="pageResults('{$startAt}');"><xsl:value-of  
select="$startAt"/></a>
				</li>
			</xsl:otherwise>
		</xsl:choose>
		<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"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>



Mime
View raw message