Thanks Brian,
That worked like a treat - it has a small bug though, where it reads:
<xsl:variable name="pages" select="floor($numFound div 10)"/>
You actually want:
<xsl:variable name="pages" select="ceiling($numFound div 10)"/>
I stand corrected about XSLT limitations though :)
--Nuno
On 24 Jul 2007, at 02:27, Brian Whitman wrote:
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 > 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) < 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>