Link to home
Start Free TrialLog in
Avatar of eaweb
eawebFlag for undefined

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/customer)"/>
<xsl:variable name="selectedRowCount" select="round($mycount div $PageSize)"/>
      <xsl:for-each select="root/customer">
       <!-- Pagination logic -->
       <xsl:if test="position() &gt;= ($Page * $PageSize) + 1">
        <xsl:if test="position() &lt;= $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 &gt;= 0">&#160;
        <A>
         <xsl:attribute name="href">_dirresult?page=<xsl:value-of select="number($Page)-1"/>&amp;pagesize=<xsl:value-of
select="$PageSize"/></xsl:attribute>
          &lt;&lt;Prev
        </A>
       </xsl:when>
       <xsl:otherwise>
        <!-- display something else -->
       </xsl:otherwise>
      </xsl:choose>
     
      <xsl:if test="$selectedRowCount &gt; 1">
       &#160;<b class="blacktext"><xsl:value-of select="number($Page)+1"/>&#160;of&#160;<xsl:value-of
select="number($selectedRowCount)"/></b>&#160;
      </xsl:if>
               
      <!-- Next link for pagination -->
      <xsl:choose>
       <xsl:when test="number($Page)+1 &lt; number($selectedRowCount)">&#160;
        <A>
         <xsl:attribute name="href">_dirresult?page=<xsl:value-of select="number($Page)+1"/>&amp;pagesize=<xsl:value-of
select="$PageSize"/></xsl:attribute>
          Next&gt;&gt;
        </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
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eaweb

ASKER

hi i have the following:

**********************************

<?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="maxBeforeAfterCurrent" select="15" />


<xsl:template name="tplPaging">
 
        <!-- Calculate the maximum number of pages to show in the paging component -->
        <xsl:variable name="numberOfPages" select="floor((number($numberOfItems)-1) div $itemsPerPage)+1"/>
 
        <!-- 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=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="images/eibStatement.css" rel="stylesheet" type="text/css" />
<link href="images/printStatement.css" rel="stylesheet" type="text/css" media="print" />
<script type="text/javascript" src="validateStm.js"></script>
</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="maxBeforeAfterCurrent" select="15" /> what is it exactly

as current page i have Pagenr.

how must i configure what i have to suite the code?
Avatar of eaweb

ASKER

ok i got it working it with this code on top:

<xsl:variable name="googlestylepagecount" select="count(cas/cap)"/>
<xsl:variable name="googlestylemaxpagecount" select="round($googlestylepagecount div $PageSize)"/>

<xsl:param name="numberOfItems" select="$googlestylemaxpagecount" />
<xsl:param name="currentPage" select="number($PageNr + 1)"  />
<xsl:param name="itemsPerPage" select="1" />
<xsl:param name="maxBeforeAfterCurrent" select="9" />
Avatar of eaweb

ASKER

great!!!
Great that it works now! Glad I could've been of some help