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的第一个节点,因此它对应的节点就是
在分页中我们需要输出合适的数据,,因此我们用一个 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!

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.

The steps to create an RSS document are as follows: 1. Write in XML format, with the root element, including the elements. 2. Add, etc. elements to describe channel information. 3. Add elements, each representing a content entry, including,,,,,,,,,,,. 4. Optionally add and elements to enrich the content. 5. Ensure the XML format is correct, use online tools to verify, optimize performance and keep content updated.

The core role of XML in RSS is to provide a standardized and flexible data format. 1. The structure and markup language characteristics of XML make it suitable for data exchange and storage. 2. RSS uses XML to create a standardized format to facilitate content sharing. 3. The application of XML in RSS includes elements that define feed content, such as title and release date. 4. Advantages include standardization and scalability, and challenges include document verbose and strict syntax requirements. 5. Best practices include validating XML validity, keeping it simple, using CDATA, and regularly updating.


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

Dreamweaver CS6
Visual web development tools