Я пытаюсь реализовать пейджинг в xml с помощью этого кода и обойти его, чтобы он работал. в то время как он работает отлично, есть небольшая проблема, когда я нажимаю на кнопку NEXT, он продолжает перезагружать страницу с теми же начальными записями. он не выводит пользователя на следующую страницу.
я наткнулся на эту ссылку, в которой у постера была аналогичная проблема, и, похоже, из параметров ответов нужно передать. однако, парень в этой ссылке использовал MM_XSLTransform, а я нет. поэтому, когда я пытаюсь реализовать этот код в index.php:
$xsl->addParameter("Page", $_GET["Page"]); $xsl->addParameter("PageSize", $_GET["PageSize"]);
он вызывает ошибку:
Fatal error: Call to undefined method XSLTProcessor::addParameter()
ОБНОВЛЕНО
PHP-код:
<?php error_reporting(E_ALL); ini_set("display_errors", 1); $xmldoc = new DOMDocument(); if(!file_exists('test.xml')){ echo "Sorry this file does not exists!"; exit(); } else { $xmldoc->load('test.xml', LIBXML_NOBLANKS); // Load up the XSL file $xslDoc = new DomDocument; $xslDoc->load("test.xsl"); $xsl = new XSLTProcessor; $xsl->importStyleSheet($xslDoc); $xsl->setParameter(null, 'Page', $_GET['Page']); $xsl->setParameter(null, 'PageSize', $_GET['PageSize']); // apply the transformation echo $xsl->transformToXml($xmldoc); } ?>
XSL:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <!-- XML Parameters --> <xsl:param name="Page" select="0" /> <xsl:param name="PageSize" select="5" /> <xsl:template match="/"> <xsl:variable name="mycount" select="count(root/verse)"/> <xsl:variable name="selectedRowCount" select="floor((number($mycount)-1) div $PageSize)+1"/> <div> <div> <xsl:value-of select="root/title"/> </div> <div> <p><xsl:value-of select="root/introduction"/></p> </div> <div> <xsl:for-each select="root/verse"> <xsl:if test="position() >= ($Page * $PageSize) + 1"> <xsl:if test="position() <= $PageSize + ($PageSize * $Page)"> <div><xsl:value-of select="p"/></div> <br /> <div><xsl:value-of select="trla"/></div> <br /> <div><xsl:value-of select="trli"/></div> <br /> </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">index.php?page=<xsl:value-of select="number($Page)-1"/>&pagesize=<xsl:value-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: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 < number($selectedRowCount)"> <A> <xsl:attribute name="href">index.php?page=<xsl:value-of select="number($Page)+1"/>&pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> Next>> </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose> </div> </div> </xsl:template> </xsl:stylesheet>
в<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <!-- XML Parameters --> <xsl:param name="Page" select="0" /> <xsl:param name="PageSize" select="5" /> <xsl:template match="/"> <xsl:variable name="mycount" select="count(root/verse)"/> <xsl:variable name="selectedRowCount" select="floor((number($mycount)-1) div $PageSize)+1"/> <div> <div> <xsl:value-of select="root/title"/> </div> <div> <p><xsl:value-of select="root/introduction"/></p> </div> <div> <xsl:for-each select="root/verse"> <xsl:if test="position() >= ($Page * $PageSize) + 1"> <xsl:if test="position() <= $PageSize + ($PageSize * $Page)"> <div><xsl:value-of select="p"/></div> <br /> <div><xsl:value-of select="trla"/></div> <br /> <div><xsl:value-of select="trli"/></div> <br /> </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">index.php?page=<xsl:value-of select="number($Page)-1"/>&pagesize=<xsl:value-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: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 < number($selectedRowCount)"> <A> <xsl:attribute name="href">index.php?page=<xsl:value-of select="number($Page)+1"/>&pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> Next>> </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose> </div> </div> </xsl:template> </xsl:stylesheet>
в<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <!-- XML Parameters --> <xsl:param name="Page" select="0" /> <xsl:param name="PageSize" select="5" /> <xsl:template match="/"> <xsl:variable name="mycount" select="count(root/verse)"/> <xsl:variable name="selectedRowCount" select="floor((number($mycount)-1) div $PageSize)+1"/> <div> <div> <xsl:value-of select="root/title"/> </div> <div> <p><xsl:value-of select="root/introduction"/></p> </div> <div> <xsl:for-each select="root/verse"> <xsl:if test="position() >= ($Page * $PageSize) + 1"> <xsl:if test="position() <= $PageSize + ($PageSize * $Page)"> <div><xsl:value-of select="p"/></div> <br /> <div><xsl:value-of select="trla"/></div> <br /> <div><xsl:value-of select="trli"/></div> <br /> </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">index.php?page=<xsl:value-of select="number($Page)-1"/>&pagesize=<xsl:value-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: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 < number($selectedRowCount)"> <A> <xsl:attribute name="href">index.php?page=<xsl:value-of select="number($Page)+1"/>&pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> Next>> </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose> </div> </div> </xsl:template> </xsl:stylesheet>
в<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <!-- XML Parameters --> <xsl:param name="Page" select="0" /> <xsl:param name="PageSize" select="5" /> <xsl:template match="/"> <xsl:variable name="mycount" select="count(root/verse)"/> <xsl:variable name="selectedRowCount" select="floor((number($mycount)-1) div $PageSize)+1"/> <div> <div> <xsl:value-of select="root/title"/> </div> <div> <p><xsl:value-of select="root/introduction"/></p> </div> <div> <xsl:for-each select="root/verse"> <xsl:if test="position() >= ($Page * $PageSize) + 1"> <xsl:if test="position() <= $PageSize + ($PageSize * $Page)"> <div><xsl:value-of select="p"/></div> <br /> <div><xsl:value-of select="trla"/></div> <br /> <div><xsl:value-of select="trli"/></div> <br /> </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">index.php?page=<xsl:value-of select="number($Page)-1"/>&pagesize=<xsl:value-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: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 < number($selectedRowCount)"> <A> <xsl:attribute name="href">index.php?page=<xsl:value-of select="number($Page)+1"/>&pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> Next>> </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose> </div> </div> </xsl:template> </xsl:stylesheet>
в<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <!-- XML Parameters --> <xsl:param name="Page" select="0" /> <xsl:param name="PageSize" select="5" /> <xsl:template match="/"> <xsl:variable name="mycount" select="count(root/verse)"/> <xsl:variable name="selectedRowCount" select="floor((number($mycount)-1) div $PageSize)+1"/> <div> <div> <xsl:value-of select="root/title"/> </div> <div> <p><xsl:value-of select="root/introduction"/></p> </div> <div> <xsl:for-each select="root/verse"> <xsl:if test="position() >= ($Page * $PageSize) + 1"> <xsl:if test="position() <= $PageSize + ($PageSize * $Page)"> <div><xsl:value-of select="p"/></div> <br /> <div><xsl:value-of select="trla"/></div> <br /> <div><xsl:value-of select="trli"/></div> <br /> </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">index.php?page=<xsl:value-of select="number($Page)-1"/>&pagesize=<xsl:value-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: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 < number($selectedRowCount)"> <A> <xsl:attribute name="href">index.php?page=<xsl:value-of select="number($Page)+1"/>&pagesize=<xsl:value-of select="$PageSize"/></xsl:attribute> Next>> </A> </xsl:when> <xsl:otherwise> <!-- display something else --> </xsl:otherwise> </xsl:choose> </div> </div> </xsl:template> </xsl:stylesheet>