I've been working with some paging. Taking base in what Nibble did: nibble.be/?p=11
Now i have 20 pages in the paging, and it's slowly growing. Could anyone helt me making, so it looks something like: 1 2 3 4 5 6 7 8 ... (ind the begining) and then later: 1 2 3 4 ... 9 10 11 12 - hope you get the drift ;)
I haven't got much time today to help work through your XSLT specifically, but I've posted up my own generic pagination XSLT (along with how to include it in an example XSLT) over on GitHub, take a look: https://gist.github.com/1122148 - it does the "Google style" distancing of the page numbers too!
Feel free to use it, or take the good bits from it ... all good.
I get shown 21 pages, but when i "extract" $count, it only says 20. How come, when i get to page 17, it goes all the way up to page 21? I think I'm just missing a "-1" somewhere - can you show mere where?
<!-- each paged set of results is listed, with a link to that page set --> <xsl:call-template name="pageNumbers"> <xsl:with-param name="pageIndex" select="1" /> <xsl:with-param name="page" select="$page" /> <xsl:with-param name="matchedNodes" select="$matchedNodes" /> <xsl:with-param name="qs" select="$qs" /> </xsl:call-template>
<!-- show a maximum of nine paged sets on either side of the current paged set; just like Google does it --> <xsl:if test="($distanceFromCurrent > -6 and $distanceFromCurrent < 6)"> <xsl:choose> <xsl:when test="$pageIndex = $page"> <a href="#" class="paging-number-sel"><xsl:value-of select="$pageIndex"/></a> </xsl:when> <xsl:otherwise> <!--<a class="paging-number" href="{concat('?page=', $pageIndex, $qs)}" title="Page {$pageIndex}">--> <a class="paging-number" href="{ucomponents.urls:AppendOrUpdateQueryString('page',$pageIndex)}" title="Page {$pageIndex}"> <xsl:value-of select="$pageIndex" /> </a> </xsl:otherwise> </xsl:choose> </xsl:if>
<!-- recursively call the template for all the paged sets --> <xsl:if test="$pageIndex * $resultsPerPage < count($matchedNodes)"> <xsl:call-template name="pageNumbers"> <xsl:with-param name="pageIndex" select="$pageIndex + 1" /> <xsl:with-param name="page" select="$page" /> <xsl:with-param name="matchedNodes" select="$matchedNodes" /> <xsl:with-param name="qs" select="$qs" /> </xsl:call-template> </xsl:if>
XSLT Paging Google-style
Hey all,
I've been working with some paging. Taking base in what Nibble did: nibble.be/?p=11
Now i have 20 pages in the paging, and it's slowly growing. Could anyone helt me making, so it looks something like: 1 2 3 4 5 6 7 8 ... (ind the begining) and then later: 1 2 3 4 ... 9 10 11 12 - hope you get the drift ;)
This is my code:
Thx in advance.
// Peter
Hi Peter,
I haven't got much time today to help work through your XSLT specifically, but I've posted up my own generic pagination XSLT (along with how to include it in an example XSLT) over on GitHub, take a look: https://gist.github.com/1122148 - it does the "Google style" distancing of the page numbers too!
Feel free to use it, or take the good bits from it ... all good.
Cheers, Lee.
Hey Lee,
Thank you very much, you get a solved for this.
However, I have one tiny question.
When using the code (slightly modified)
I get shown 21 pages, but when i "extract" $count, it only says 20. How come, when i get to page 17, it goes all the way up to page 21?
I think I'm just missing a "-1" somewhere - can you show mere where?
Cheers, Peter
Hello all,
I am doing some change for paging. if any querystring is there in url so previous xslt is not working properly..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ucomponents.urls="urn:ucomponents.urls"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:variable name="resultsPerPage" select="number(6)" />
<xsl:template name="pagination">
<xsl:param name="page" />
<xsl:param name="matchedNodes" />
<xsl:param name="qs" />
<div class="pagginginarea">
<!-- previous page -->
<xsl:if test="$page > 1">
<!--<a class="paging-text-prev" href="{concat('?page=', $page - 1, $qs)}" title="Previous page">Prev</a> -->
<a class="paging-text-prev" href="{ucomponents.urls:AppendOrUpdateQueryString('page',$page - 1)}" title="Previous page">Prev</a>
</xsl:if>
<!-- each paged set of results is listed, with a link to that page set -->
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1" />
<xsl:with-param name="page" select="$page" />
<xsl:with-param name="matchedNodes" select="$matchedNodes" />
<xsl:with-param name="qs" select="$qs" />
</xsl:call-template>
<!-- next page -->
<xsl:if test="$page * $resultsPerPage < count($matchedNodes)">
<!--<a class="paging-text-next" href="{concat('?page=', $page + 1, $qs)}" title="Next page">Next</a>-->
<a class="paging-text-next" href="{ucomponents.urls:AppendOrUpdateQueryString('page',$page + 1)}" title="Next page">Next</a>
</xsl:if>
</div>
</xsl:template>
<xsl:template name="pageNumbers">
<xsl:param name="page" />
<xsl:param name="pageIndex" />
<xsl:param name="matchedNodes" />
<xsl:param name="qs" />
<xsl:variable name="distanceFromCurrent" select="$pageIndex - $page"/>
<!-- show a maximum of nine paged sets on either side of the current paged set; just like Google does it -->
<xsl:if test="($distanceFromCurrent > -6 and $distanceFromCurrent < 6)">
<xsl:choose>
<xsl:when test="$pageIndex = $page">
<a href="#" class="paging-number-sel"><xsl:value-of select="$pageIndex"/></a>
</xsl:when>
<xsl:otherwise>
<!--<a class="paging-number" href="{concat('?page=', $pageIndex, $qs)}" title="Page {$pageIndex}">-->
<a class="paging-number" href="{ucomponents.urls:AppendOrUpdateQueryString('page',$pageIndex)}" title="Page {$pageIndex}">
<xsl:value-of select="$pageIndex" />
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!-- recursively call the template for all the paged sets -->
<xsl:if test="$pageIndex * $resultsPerPage < count($matchedNodes)">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="$pageIndex + 1" />
<xsl:with-param name="page" select="$page" />
<xsl:with-param name="matchedNodes" select="$matchedNodes" />
<xsl:with-param name="qs" select="$qs" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Thanks...
is working on a reply...