XML practice Example 3: Dynamic paging

Source: Internet
Author: User
Tags xml example
PHP100 is the first professional website in China to share PHP resources. It also provides a PHP Chinese communication community. For PHP study researchers: The latest PHP information, original content, open source code and PHP video tutorials and other related content. [Guide] dynamic paging is used to facilitate users to view large volumes of data. Therefore, the paging function is the most common and commonly used function module on websites. In the past, information is linked to the database on pages, and each click must be supported by the background database. In this way

In order to facilitate users to view large volumes of data, we will use dynamic paging. Therefore, the paging function is the most common and most commonly used functional module we have seen on the website. In the past, information is linked to the database on pages, and each click must be supported by the background database. This not only increases the server load, but also seriously affects the user's browsing speed.
Imagine what effect would it have if we put the paging function on the client? Look at the design below! .

Materials:
Dynamic paging of xml volumes
There are two files: pages. xml and pages. xsl.

Purpose:
Place the paging function on the client. Filter data without refreshing a new page, which effectively improves the efficiency of data browsing.
Effect:
Browse here
Code:
Pages. xml

 
 
   
      
   
    
1
       
   
    
Sailflying
       
   
    
A simple paging
       
   
    
2002-1-11 17:35:33
       
   
    
XML topics
     
    
      
   
    
2
       
   
    
Flyingbird
       
   
    
Marry you. it hurts you.
       
   
    
2001-09-06 12:45:51
       
   
    
Irrigation essence
     
    
      
   
    
3
       
   
    
Accounts
       
   
    
Application of regular expressions in UBB forum
       
   
    
2001-11-23 21:02:16
       
   
    
Web Programming Essence
     
    
      
   
    
4
       
   
    
Taiyilang
       
   
    
End-of-year classic rudder gathering full manual v0.1
       
   
    
2000-12-08 10:22:48
       
   
    
Forum irrigation area
     
    
      
   
    
5
       
   
    
Mmkk
       
   
    
Asp error message summary
       
   
    
2001-10-13 16:39:05
       
   
    
Javascript script
     
  
 




Pages. xsl

 
 
  
   Practical tips for XML volumes (3): Dynamic paging
   Script
     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); }  
   Script
   

Practical tips for XML volumes (3): Dynamic paging

HomepagePrevious PageNext page Last page

No. Name Topic Posting time Category





Explanation:
1) search. xml is a data file, and we believe there will be no problem.
2) search. xsl is a format file. There are several points to note.

(1) in the script:

Nodes=source.doc umentElement. childNodes;
Function: find all nodes. Nodes. length indicates the total number of nodes that meet the conditions.

SortField = document. your document. selectSingleNode ("// @ expr ");
The role is to find the first node with an attribute of expr, so the corresponding node is

Therefore, the value of expr during the first onLoad is
Childnumber (this) <= 1 & childnumber (this)> = 2
About> <you may be more familiar with it. So what is it? It is "and.
You can find some other information in XML.



Parameter description:
OnePageNum: number of data displayed on each page
PageNum: current page number
XMLPageNum: total number of pages
FirstNum: the first data value on the current page.
LastNum: The last data value of the current page.


(2) text:


We need to output appropriate data in the paging, so we use an if condition to control it.
At the beginning, we need to output only the values of the first two nodes.

Childnumber (this)
Purpose: return the number of the current node in its parent node list. the first node in the list is numbered 1 by default.
In the page, we determine the page number of the node.
Expr
I don't know if you have found it. we used test for the first two times, but expr is used for this.
There are some differences between them, and their usage is also different.
Expr -- a scripting expression. the calculation result is "true" or "false". if the result is "true, the content is displayed in the output (this attribute can be omitted ).
Test ── test conditions for source data.

Homepage
The role is to bring the data back to the previous page. Other buttons have similar functions.



Add: how to use the XML example file

1) save the two files in each example by file name.
2) use a browser to browse XML files. This is what you will see. it should be good!

The above is the XML practice. Volume 3: Details of dynamic paging. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.