XML Practical Cheats Volume 3: Dynamic Pagination
[导读] 为了方便用户查看大批量数据,我们会用到动态分页,因此分页功能是我们在网站上见过的最普遍也是最常用的一个功能模块了。而以往的信息分页都是连接到数据库的,每一次点击都必须要后台数据库的支持。这样不但服
为了方便用户查看大批量数据,我们会用到动态分页,因此分页功能是我们在网站上见过的最普遍也是最常用的一个功能模块了。而以往的信息分页都是连接到数据库的,每一次点击都必须要后台数据库的支持。这样不但服务器的负担加重,而且严重的影响用户浏览的速度.
试想,如果把分页的功能放到客户端,那会产生什么样的效果呢?呵呵,看看下面的设计吧! 。
材料:
xml卷之动态分页
有2个文件:pages.xml 和 pages.xsl
作用:
把分页的功能放到客户端。在不刷新页面的情况下对数据进行过滤筛选,有效的提高浏览数据功能的效率。
效果:
浏览这里
代码:
pages.xml
<?xml version="1.0" encoding="gb2312" ?> <?xml-stylesheet type="text/xsl" href="pages.xsl" ?> <BlueIdea> <team> <blue_ID>1</blue_ID> <blue_name>Sailflying</blue_name> <blue_text>一个简单的分页</blue_text> <blue_time>2002-1-11 17:35:33</blue_time> <blue_class>XML专题</blue_class> </team> <team> <blue_ID>2</blue_ID> <blue_name>flyingbird</blue_name> <blue_text>嫁给你,是要你疼的</blue_text> <blue_time>2001-09-06 12:45:51</blue_time> <blue_class>灌水精华</blue_class> </team> <team> <blue_ID>3</blue_ID> <blue_name>苛子</blue_name> <blue_text>正则表达式在UBB论坛中的应用</blue_text> <blue_time>2001-11-23 21:02:16</blue_time> <blue_class>Web 编程精华</blue_class> </team> <team> <blue_ID>4</blue_ID> <blue_name>太乙郎</blue_name> <blue_text>年末经典分舵聚会完全手册 v0.1</blue_text> <blue_time>2000-12-08 10:22:48</blue_time> <blue_class>论坛灌水区</blue_class> </team> <team> <blue_ID>5</blue_ID> <blue_name>mmkk</blue_name> <blue_text>asp错误信息总汇</blue_text> <blue_time>2001-10-13 16:39:05</blue_time> <blue_class>javascript脚本</blue_class> </team> </BlueIdea>
pages.xsl
<?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <head> <title> XML卷之实战锦囊(3):动态分页</title> <style> body,BlueIdea,team,blue_ID,blue_name,blue_text,blue_time,blue_class{ font: 12px "宋体", "Arial", "Times New Roman"; } table { font-size: 12px; border: 0px double; border-color: #99CC99 #99CC99 #CCCCCC #CCCCCC; cellpadding:3;cellspacing:3; bgcolor:#eeeeee; text-decoration: blink} span { font-size: 12px; color: red; } .keybutton { cursor:hand; font-size: 12px; color: #003300; background: #ffffff; border: 0px solid;} </style> <script> <xsl:comment> <![CDATA[ var OnePageNum=2; var PageNum=1; var XMLPageNum=1; function pages(Num) { stylesheet=document.XSLDocument; source=document.XMLDocument; nodes=source.documentElement.childNodes; len=nodes.length; for(i=1;i<=(len/OnePageNum);i++); XMLPageNum=i; var firstNum=0; var lastNume=0; if (Num=="first") {PageNum=1;} if (Num=="PRevious") {if (PageNum>1) PageNum -=1;} if (Num=="next") {if (PageNum<XMLPageNum) PageNum +=1;} if (Num=="last") {PageNum =XMLPageNum;} sortField=document.XSLDocument.selectSingleNode("//@expr"); firstNum=OnePageNum*(PageNum-1)+1; lastNum=OnePageNum*(PageNum-1)+OnePageNum; text="childnumber(this)>="+firstNum+" & childnumber(this)<="+lastNum; sortField.value=text; Layer1.innerHTML=source.documentElement.transformNode(stylesheet); } ]]> </xsl:comment> </script> </head> <body> <p align="center"><span>XML卷之实战锦囊(3):动态分页</span></p> <table align="center" width="500" > <tr> <td> <button id="cmdfirstPage" class="keybutton" onclick="pages('first');" >首页</button> <button id="cmdpreviousPage" class="keybutton" onclick="pages('previous');" >上一页</button> <button id="cmdnextPage" class="keybutton" onclick="pages('next');">下一页</button> <button id="cmdlastPage" class="keybutton" onclick="pages('last');">尾页</button> </td> </tr> </table> <p id="Layer1" name="Layer1"> <xsl:apply-templates select="BlueIdea" /></p> </body> </html> </xsl:template> <xsl:template match="BlueIdea"> <table width="500" border="1" align="center" cellpadding="1" cellspacing="1" bordercolordark="#ffffff" bordercolorlight="#ADAAAD"> <tr bgcolor="#FFCC99" align="center"> <td>编号</td> <td>姓名</td> <td>主题</td> <td>发表时间</td> <td>归类</td> </tr> <xsl:apply-templates select="team" order-by="blue_ID"/> </table> </xsl:template> <xsl:template match="team"> <xsl:if expr="childnumber(this)>=1 & childnumber(this)<=2 "> <tr align="center"> <xsl:apply-templates select="blue_ID" /> <xsl:apply-templates select="blue_name" /> <xsl:apply-templates select="blue_text" /> <xsl:apply-templates select="blue_time" /> <xsl:apply-templates select="blue_class" /> </tr> </xsl:if> </xsl:template> <xsl:template match="blue_ID"> <td bgcolor="#eeeeee"> <xsl:value-of /> </td> </xsl:template> <xsl:template match="blue_name"> <td> <xsl:value-of /> </td> </xsl:template> <xsl:template match="blue_text"> <td> <xsl:value-of /> </td> </xsl:template> <xsl:template match="blue_time"> <td> <xsl:value-of /> </td> </xsl:template> <xsl:template match="blue_class"> <td> <xsl:value-of /> </td> </xsl:template> </xsl:stylesheet>
讲解:
1)search.xml 是数据文件,相信大家都不会有问题。
2)search.xsl 是格式文件,有几个地方要注意。
(1)脚本中:
nodes=source.documentElement.childNodes;
作用是:找到所有的节点。nodes.length就是符合条件的总节点数
sortField=document.XSLDocument.selectSingleNode("//@expr");
作用是:找到有属性为expr的第一个节点,因此它对应的节点就是
因此在初次onLoad的时候expr的value值是
childnumber(this)<=1 & childnumber(this)>=2
关于 > < 大家可能熟悉多了。那&是什么呢? 它就是“与”了.
大家可以在XML的书中找到其它的一些。
参数说明:
OnePageNum:每页显示的数据数
PageNum:当前页数
XMLPageNum:总页数
firstNum:当前页的第一条数据值
lastNum:当前页的最后一条数据值
(2)文本中:
在分页中我们需要输出合适的数据,,因此我们用一个 if 判断条件来控制。
在初始的时候我们要求只输出最前的两个节点的数值。
childnumber(this)
作用:返回当前节点在它的上级节点列表中的编号,列表中的第一个节点默认编号为1。
在分页中我们就是根据节点的编号来判断它属于第几页。
expr
不知道大家发现没有,前两次我们用到的都是 test ,可这个我们用的却是expr。
它们之间有一定的区别,用法也不相同。
expr ── 脚本语言表达式,计算结果为"真"或"假";如果结果为"真",且通过test,则在输出中显示其中内容(可省略此项属性)。
test ── 源数据测试条件。
作用是让数据回到最前一页。其它按钮的作用类似。
补充一点: XML例子文件的使用方法
1)将每个例子里的两个文件按照文件名分别保存。
2)用浏览器浏览XML文件即可。这是你会看到效果,应该不错吧!
The above is the detailed content of XML Practical Cheats Volume 3: Dynamic Pagination. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
