Motivation:
The sorting function makes the data on our page appear more humane, which is a very common functional effect we have seen on websites. In the past, automatic sorting was done with a lot of script code, which was difficult for ordinary enthusiasts. However, it is much simpler to deal with it using XML. Make your page more gorgeous, haha, are you excited too!
Materials:
Dynamic sorting of XML volumes
There are 2 files: paixu.xml and paixu.xsl
Function:
Update without refreshing the page Re-order and display the data according to the user's own needs, effectively improving the data interaction function and making their pages more colorful.
Effect:
Browse here
Code:
paixu.xml
<?xml version="1.0" encoding="gb2312" ?> <?xml-stylesheet type="text/xsl" href="paixu.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>
paixu.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卷之实战锦囊(1):动态排序</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; } </style> <script> function taxis(x) { stylesheet=document.XSLDocument; source=document.XMLDocument; sortField=document.XSLDocument.selectSingleNode("//@order-by"); sortField.value=x; Layer1.innerHTML=source.documentElement.transformNode(stylesheet); } </script> </head> <body> <p align="center"><span>XML卷之实战锦囊(1):动态排序</span></p> <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 style="cursor:s-resize" onClick="taxis('blue_ID')">编号</td> <td style="cursor:s-resize" onClick="taxis('blue_name')">姓名</td> <td style="cursor:s-resize" onClick="taxis('blue_text')">主题</td> <td style="cursor:s-resize" onClick="taxis('blue_time')">发表时间</td> <td style="cursor:s-resize" onClick="taxis('blue_class')">归类</td> </tr> <xsl:apply-templates select="team" order-by="blue_ID"/> </table> </xsl:template> <xsl:template match="team"> <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: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>
Explanation:
1) paixu.xml is a data file, I believe everyone will have no problem.
2) paixu.xsl is a format file, there are several things to pay attention to.
(1) In the script:
sortField=document.XSLDocument.selectSingleNode("//@order-by");
The function is: find the first one with the attribute order-by node, so its corresponding node is
Therefore, the value of order-by during the first onLoad is blue_ID .
And we achieve the purpose of sorting by redefining the value of order-by.
Layer1.innerHTML=source.documentElement.transformNode(stylesheet);
The function is to change Layer1 after converting the XML data, so after passing out the parameter 'blue_name',
<td style="cursor:s-resize" onClick="taxis('blue_name)">姓名</td>
We change the value of order-by The value is modified to 'blue_name', that is, 'blue_name' is used as the sorting method.
Then display the new sorted content by redisplaying the innerHTML value of Layer1.
(2) In the text:
order-by
This cannot be missing, otherwise you will not be able to find it. Take a look at the effect! !
<?xml version="1.0" encoding="gb2312" ?>
In most XML textbooks, encoding="gb2312" is rarely added to the code displayed.
Therefore, when we use Chinese in XML, an error will be reported. The reason is that this is not written. Statement.
Postscript:
After everyone is familiar with the idea of dynamic sorting, you will find that our implementation method is actually very simple.
Just modify the order-by value and then display it again.
We still follow this idea in the functions of dynamic query and dynamic paging.
The above is the practical tips for XML volumes (1): dynamic sorting content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

When processing XML and RSS data, you can optimize performance through the following steps: 1) Use efficient parsers such as lxml to improve parsing speed; 2) Use SAX parsers to reduce memory usage; 3) Use XPath expressions to improve data extraction efficiency; 4) implement multi-process parallel processing to improve processing speed.

RSS2.0 is an open standard that allows content publishers to distribute content in a structured way. It contains rich metadata such as titles, links, descriptions, release dates, etc., allowing subscribers to quickly browse and access content. The advantages of RSS2.0 are its simplicity and scalability. For example, it allows custom elements, which means developers can add additional information based on their needs, such as authors, categories, etc.

RSS is an XML-based format used to publish frequently updated content. 1. RSSfeed organizes information through XML structure, including title, link, description, etc. 2. Creating RSSfeed requires writing in XML structure, adding metadata such as language and release date. 3. Advanced usage can include multimedia files and classified information. 4. Use XML verification tools during debugging to ensure that the required elements exist and are encoded correctly. 5. Optimizing RSSfeed can be achieved by paging, caching and keeping the structure simple. By understanding and applying this knowledge, content can be effectively managed and distributed.

RSS is an XML-based format used to publish and subscribe to content. The XML structure of an RSS file includes a root element, an element, and multiple elements, each representing a content entry. Read and parse RSS files through XML parser, and users can subscribe and get the latest content.

XML has the advantages of structured data, scalability, cross-platform compatibility and parsing verification in RSS. 1) Structured data ensures consistency and reliability of content; 2) Scalability allows the addition of custom tags to suit content needs; 3) Cross-platform compatibility makes it work seamlessly on different devices; 4) Analytical and verification tools ensure the quality and integrity of the feed.

The implementation of RSS in XML is to organize content through a structured XML format. 1) RSS uses XML as the data exchange format, including elements such as channel information and project list. 2) When generating RSS files, content must be organized according to specifications and published to the server for subscription. 3) RSS files can be subscribed through a reader or plug-in to automatically update the content.

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing


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

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),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
