lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ard Schrijvers" <a.schrijv...@hippo.nl>
Subject RE: Pagination of results and XSLT.
Date Tue, 24 Jul 2007 09:20:13 GMT

> 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.

I have been using similar xsls like you describe below in the past, but....I think after 3
years of using it I came to realize (500 internal server error) that it can lead to nasty
errors when you have a recursive call like (though I am not sure wether it depends on your
xslt processor, al least xalan has the problem)

When the number of pages becomes extremely large (depending on your memory settings) this
piece of xsl will result in StackOverflow's. Just try my piece here below, and increase "end"
parameter. You will get it pretty soon. So, IMO, paging is correctly done either by returning
a correct paging block of xml by solr (where you can define the paging type, like only the
middle pages visible, or jumping mode were you see 1-10, and then at 11 you see 11-20, etc)
or you use some xsl extension java class to do it.

OTH, I can only confirm this stack overflow behavior for xalan....

Regards Ard

<xsl:call-template name="loop">
      <xsl:with-param name="start" select="0"/>
      <xsl:with-param name="end" select="600"/>
</xsl:call-template> 

<xsl:template name="loop">
        <xsl:param name="start"/>
        <xsl:param name="end"/>
        
        <a><xsl:value-of select="$start"/></a>
        
        <xsl:if test="$start &lt; $end">
            <xsl:call-template name="loop">
                <xsl:with-param name="start" select="$start + 1"/>
                <xsl:with-param name="end" select="$end"/>
            </xsl:call-template>
        </xsl:if>    
        
 </xsl:template>

> 
> 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