eaweb
asked on
google style pagination in xslt
hi, how can i put a google style pagination (show fisrt 10 pages etc.. and when click on 10 show the next ten etc....) in between below previous and next links?
here the xslt i am using
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="3.2" encoding="ISO-8859-1"/>
<xsl:param name="Page" select="0" />
<xsl:param name="PageSize" select="1" />
<xsl:template name="results" match="/">
<xsl:variable name="mycount" select="count(root/custome r)"/>
<xsl:variable name="selectedRowCount" select="round($mycount div $PageSize)"/>
<xsl:for-each select="root/customer">
<!-- Pagination logic -->
<xsl:if test="position() >= ($Page * $PageSize) + 1">
<xsl:if test="position() <= $PageSize + ($PageSize * $Page)">
<!-- Do display here -->
</xsl:if>
</xsl:if>
</xsl:for-each>
<!-- Prev link for pagination -->
<xsl:choose>
<xsl:when test="number($Page)-1 >= 0"> 
<A>
<xsl:attribute name="href">_dirresult?pag e=<xsl:val ue-of select="number($Page)-1"/> &pages ize=<xsl:v alue-of
select="$PageSize"/></xsl: attribute>
<<Prev
</A>
</xsl:when>
<xsl:otherwise>
<!-- display something else -->
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$selectedRowCount > 1">
 <b class="blacktext"><xsl:val ue-of select="number($Page)+1"/>  of&# 160;<xsl:v alue-of
select="number($selectedRo wCount)"/> </b> 
</xsl:if>
<!-- Next link for pagination -->
<xsl:choose>
<xsl:when test="number($Page)+1 < number($selectedRowCount)" > 
<A>
<xsl:attribute name="href">_dirresult?pag e=<xsl:val ue-of select="number($Page)+1"/> &pages ize=<xsl:v alue-of
select="$PageSize"/></xsl: attribute>
Next>>
</A>
</xsl:when>
<xsl:otherwise>
<!-- display something else -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
i found this code (see below link) but don't know how to include it in the code to make it work. please some help, thanks.
http://briancaos.wordpress.com/2009/01/28/create-a-google-style-paging-component-in-xslt/
here the xslt i am using
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="3.2" encoding="ISO-8859-1"/>
<xsl:param name="Page" select="0" />
<xsl:param name="PageSize" select="1" />
<xsl:template name="results" match="/">
<xsl:variable name="mycount" select="count(root/custome
<xsl:variable name="selectedRowCount" select="round($mycount div $PageSize)"/>
<xsl:for-each select="root/customer">
<!-- Pagination logic -->
<xsl:if test="position() >= ($Page * $PageSize) + 1">
<xsl:if test="position() <= $PageSize + ($PageSize * $Page)">
<!-- Do display here -->
</xsl:if>
</xsl:if>
</xsl:for-each>
<!-- Prev link for pagination -->
<xsl:choose>
<xsl:when test="number($Page)-1 >= 0"> 
<A>
<xsl:attribute name="href">_dirresult?pag
select="$PageSize"/></xsl:
<<Prev
</A>
</xsl:when>
<xsl:otherwise>
<!-- display something else -->
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$selectedRowCount > 1">
 <b class="blacktext"><xsl:val
select="number($selectedRo
</xsl:if>
<!-- Next link for pagination -->
<xsl:choose>
<xsl:when test="number($Page)+1 < number($selectedRowCount)"
<A>
<xsl:attribute name="href">_dirresult?pag
select="$PageSize"/></xsl:
Next>>
</A>
</xsl:when>
<xsl:otherwise>
<!-- display something else -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
i found this code (see below link) but don't know how to include it in the code to make it work. please some help, thanks.
http://briancaos.wordpress.com/2009/01/28/create-a-google-style-paging-component-in-xslt/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok i got it working it with this code on top:
<xsl:variable name="googlestylepagecount " select="count(cas/cap)"/>
<xsl:variable name="googlestylemaxpageco unt" select="round($googlestyle pagecount div $PageSize)"/>
<xsl:param name="numberOfItems" select="$googlestylemaxpag ecount" />
<xsl:param name="currentPage" select="number($PageNr + 1)" />
<xsl:param name="itemsPerPage" select="1" />
<xsl:param name="maxBeforeAfterCurren t" select="9" />
<xsl:variable name="googlestylepagecount
<xsl:variable name="googlestylemaxpageco
<xsl:param name="numberOfItems" select="$googlestylemaxpag
<xsl:param name="currentPage" select="number($PageNr + 1)" />
<xsl:param name="itemsPerPage" select="1" />
<xsl:param name="maxBeforeAfterCurren
ASKER
great!!!
Great that it works now! Glad I could've been of some help
ASKER
**************************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="3.2" encoding="ISO-8859-1"/>
<xsl:param name="PageNr" select="0" />
<xsl:param name="PageSize" select="1" />
<xsl:param name="lastOrRequested" select="0" />
<xsl:param name="requestedAcoount" select="0" />
<xsl:param name="requestedDate" select="0" />
<xsl:param name="numberOfItems" select="6493" />
<xsl:param name="currentPage" select="24" />
<xsl:param name="itemsPerPage" select="10" />
<xsl:param name="maxBeforeAfterCurren
<xsl:template name="tplPaging">
<!-- Calculate the maximum number of pages to show in the paging component -->
<xsl:variable name="numberOfPages" select="floor((number($num
<!-- Calaulate the starting position of the numbers -->
<xsl:variable name="startPage">
<xsl:choose>
<xsl:when test="$currentPage > ($maxBeforeAfterCurrent + 1)">
<xsl:value-of select="$currentPage - $maxBeforeAfterCurrent"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Calculate the ending position of the numbers -->
<xsl:variable name="endPage">
<xsl:choose>
<xsl:when test="($numberOfPages - $currentPage) > $maxBeforeAfterCurrent">
<xsl:value-of select="$currentPage + $maxBeforeAfterCurrent"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$numberOfPages"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Recursively draw the paging component -->
<ul>
<xsl:if test="$startPage > 1">
<li>
<a href="?page={$currentPage - ($maxBeforeAfterCurrent + 1)}">Previous</a>
</li>
</xsl:if>
<xsl:call-template name="tplNumber">
<xsl:with-param name="current" select="$currentPage"/>
<xsl:with-param name="number" select="$startPage"/>
<xsl:with-param name="max" select="$endPage"/>
</xsl:call-template>
<xsl:if test="($currentPage + $maxBeforeAfterCurrent) < $numberOfPages">
<li>
<a href="?page={$currentPage + $maxBeforeAfterCurrent + 1}">Next</a>
</li>
</xsl:if>
</ul>
</xsl:template>
<xsl:template name="tplNumber">
<xsl:param name="current"/>
<xsl:param name="number"/>
<xsl:param name="max"/>
<xsl:choose>
<xsl:when test="$number = $current">
<!-- Show current page without a link -->
<li class="current">
<xsl:value-of select="$number"/>
</li>
</xsl:when>
<xsl:otherwise>
<li>
<a href="?page={$number}">
<xsl:value-of select="$number"/>
</a>
</li>
</xsl:otherwise>
</xsl:choose>
<!-- Recursively call the template untill we reach the max number of pages -->
<xsl:if test="$number < $max">
<xsl:call-template name="tplNumber">
<xsl:with-param name="current" select="$current"/>
<xsl:with-param name="number" select="$number + 1"/>
<xsl:with-param name="max" select="$max"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="results" match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html;charset
<meta http-equiv="Content-Style-
<link href="images/eibStatement.
<link href="images/printStatemen
<script type="text/javascript" src="validateStm.js"></scr
</head>
<body>
<xsl:variable name="mycount" select="count(cas/cap)"/>
<xsl:variable name="selectedRowCount" select="round($mycount div $PageSize)"/>
<xsl:call-template name="tplPaging" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
**************************
my numberOfPages = selectedRowCount which is in the
<xsl:template name="results" match="/">
how do i get it in the tplpaging
the <xsl:param name="maxBeforeAfterCurren
as current page i have Pagenr.
how must i configure what i have to suite the code?