Thread: XSL pagination

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    San Jose, CA
    Posts
    36
    Rep Power
    12

    XSL pagination


    Hello all,

    I need to paginate XML feed using XSL. I found a way to do it at http://www.codeproject.com/Purgatory/pagination.asp and using the way described, I have been able to make it work, except for one thing. When I click on the previous and next link, the page does not retrieve the next (or previous data). The page refreshes to the same page (showing the same data) again, even thou the URL is changed correctly.

    XSL I am using is:

    Code:
    <?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="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"> 
             <A>
              <xsl:attribute name="href">page.php?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">
             <b class="blacktext"><xsl:value-of select="number($Page)+1"/> of 
    	<xsl:value-of select="number($selectedRowCount)"/></b> 
           </xsl:if>
    
          <!-- Next link for pagination -->
           <xsl:choose>
            <xsl:when test="number($Page)+1 &lt; number($selectedRowCount)"> 
             <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>
    Any ideas why the next (or previous data) is not being show?

    Thank you for your help.

    Ray
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Posts
    577
    Rep Power
    59
    Could you show the php code you're using to pass the parameters into the xslt?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    San Jose, CA
    Posts
    36
    Rep Power
    12
    Originally Posted by jkmyoung
    Could you show the php code you're using to pass the parameters into the xslt?

    Sure, the php code is as follows:

    Code:
    <?php
    //XMLXSL Transformation class
    require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php'); 
    ?>
    <?php
    $mm_xsl = new MM_XSLTransform();
    $mm_xsl->setXML("b.xml");
    $mm_xsl->setXSL("b.xsl");
    echo $mm_xsl->Transform();
    ?>
    The above was created in Dreamweaver. The XML feed is coming from elsewhere. The include file is processor (I believe sablotron).

    I could be wrong, but I think what is happening is that when I click on the next or previous button, the page goes back to b.php (that is itself), and since I am setting the page = 0 (<xsl: param name="Page" select="0" />), its showing me that page again. Do you think that is correct? If so, how do I fix this so that the initial page is set to 0, but subsequent pages are what ever the user selects (depending on next and previous). Of course, if I am wrong in my thinking, please ignore that....

    Any ways, any suggestions would be most welcomed. I just cant figure this one out.

    Thanks,

    Ray
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Posts
    577
    Rep Power
    59
    Yeah, it doesn't look like you're passing your parameters in anywhere, so the xsl just takes the default.

    Normally, you'd:
    1. Grab the parameters from the URL
    2. Pass these parameters into the transformation, either through an argument list, or by manipulating the DOM.

    I think you'd use the subfunction
    $mm_xsl->addParameter("Page", $_GET["Page"])
    $mm_xsl->addParameter("PageSize", $_GET["PageSize"])

    Unfortunately, I'm not entirely familiar with the MM_XSLTransform class.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    San Jose, CA
    Posts
    36
    Rep Power
    12

    Thank you


    Originally Posted by jkmyoung
    Yeah, it doesn't look like you're passing your parameters in anywhere, so the xsl just takes the default.

    Normally, you'd:
    1. Grab the parameters from the URL
    2. Pass these parameters into the transformation, either through an argument list, or by manipulating the DOM.

    I think you'd use the subfunction
    $mm_xsl->addParameter("Page", $_GET["Page"])
    $mm_xsl->addParameter("PageSize", $_GET["PageSize"])

    Unfortunately, I'm not entirely familiar with the MM_XSLTransform class.
    Hi jkmyoung,

    Sorry took me a while to get back to you, I got a new job and had put this project on the back burner. Anyway, just wanted to thank you for the solution. It worked like a charm. You rock!.

    Ray

IMN logo majestic logo threadwatch logo seochat tools logo