Dynamic query using XML and XSLT

Source: Internet
Author: User
Tags xsl xsl file xslt


Dynamic query using XML and XSLT


content:
1. Introduction
2. Concepts of XML and XSLT
3. How to use XML and XSLT for dynamic query
4. Conclusion
references
about the author


Zhuo Qun (zhuoqun@163.net)

99 research in Computer Science Department, Sun Yat-sen University

November 2001

This article proposes a method to implement dynamic query using XML and XSLT. This article first analyzes the application background of this method in practice, and then illustrates the specific implementation method with the Windows NT platform as an example.ArticleIs attached with the actualCodeFor analysis.

1. Introduction

In the past, server-side dynamic page queries were generally based on CGIProgramOr various script programs. The reason why we consider using XML and XSLT for dynamic queries is based on the following actual problems. Assuming that an aircraft manufacturing company sells its own aircraft to an airline, the aircraft manufacturer provides necessary information to the airline for routine maintenance of the aircraft. Assume that there is an aircraft part table in the aircraft manufacturer's database. Each record in the table corresponds to an airplane part and records the part number, name, and other attributes. At present, airline engineers need to query a part, or a part whose name has common characteristics. For security and performance reasons, aircraft manufacturers do not want airlines to directly find information from their own databases. Our question is how to implement such a custom query.

An easy-to-think and traditional method is that aircraft manufacturers help airlines establish databases on their own servers to store all the data, use the CGI program or script program on the server to generate dynamic pages for dynamic query. This method is still a good method in systems that require real-time data updates, but it is not required in our systems. In addition, database connection consumes a certain amount of resources. Using this method will reduce system efficiency and increase system complexity, and data transmission between different databases is complicated. Is there a more direct solution? I think with the continuous improvement and development of XML standards, using XML and XSLT technology to publish information and dynamically query information is very effective in our hypothetical practical application.

2. Concepts of XML and XSLT

XML (Extensible Markup Language) is considered a new generation of network languages with its scalability, openness, and interoperability. It was initially designed as a subset of SGML, so it retains the basic advantages of SGML, such as the concept of "abstract" Data separated from special expressions. In addition, because XML is the main media for transmitting web, it is designed as the core of a set of related technologies, including the Extensible style language XSL, XML link language, and XML namespace. Among them, XSL is fully called Extensible Stylesheet Language, which is a scalable markup language. It is a style table language for XML display. You can use a style table that is not used for the same XML file to display different content and methods. XSL consists of three parts: XSLT (XSL Transform) is a language for transforming XML documents, and XPath is a language for defining XML node paths, XML Formatting Objects is a language that defines XML display. This article mainly uses the XSLT language. Based on a series of filters and patterns contained in the style sheet, XSLT obtains an XML document (called the source document) and outputs a result tree of this document.

The biggest feature of XML is that it represents data independently from the platform. Like java, XML achieves platform independence of the program. XML can easily exchange data, so it is widely used in many aspects: global publishing, data search and retrieval, web site management, personalized Publishing, event-driven database interaction, communications between applications, and e-commerce.

3. How to use XML and XSLT for dynamic queries

One problem to solve when using XML and XSLT for dynamic query is how to pass query parameters to the XSLT file. The following code illustrates the implementation of this method on Windows NT. We use three files: uint. XML, unit. XSL, query. asp. Unit. XML is the XML document of the part list, and unit. XSL is the style table. The setting conditions are used to filter and display the content in unit. XML in a certain format. Query. ASP is a server-side ASP script program. It has two functions: one is to pass the query conditions to the Unit. in XSL, the second is to set unit. XML and unit. XSL is used to generate HTML files that can be directly displayed by the client and return them to the client. The following is a file list:

    1. unit. xml file content:

        
                    
                    
                    
                     
                     
                       ac0470 
                      
                     
                       unit0001 
                      
                     ... 
                     
                    
                      ac0470 
                     
                    
                      unit0001 
                     ... 
                     
  • Unit. XSL File Content

    <? XML version = "1.0"?> <XSL: stylesheet xmlns: XSL = "http://www.w3.org/TR/WD-xsl"> <XSL: template match = "/"> <HTML> 
  • Query. asp file content
      <% set xml = server. createobject ("Microsoft. xmldom ") XML. async = falsexml. load (server. mappath ("unit. XML ") set XSL = server. createobject ("Microsoft. xmldom ") XSL. async = falsexsl. load (server. mappath ("unit. XSL ") set root = 2.16.doc umentelementset scriptelem = XSL. createelement ("XSL: script") root. appendchild (scriptelem) set cdataelem = XSL. createcdatasection ("substr =" & request ("substr") & ""; "& _" function filter (node) {"& _" Var total; "& _" Total = node. selectsinglenode ("" Ein ""). text; "& _" Return total. indexof (substr) = 0; "& _"} ") root. lastchild. appendchild (cdataelem) XSL. save (server. mappath ("temp. XSL ") XSL. load (server. mappath ("temp. XSL ") response. write (XML. transformnode (XSL) %>  

    The above list briefly illustrates our practice. The data filtering function is partially completed, and the filter is a custom JavaScript function, it is used to check whether the current part number starts with the specified string (the string is submitted to the Web server by the user ). We can see that our practice is to customize a filter function based on the query conditions, and then insert the filter function as a node into the XSL file. This solves the problem of how to pass query parameters to the XSLT file. By now, the entire dynamic query function has been fully implemented.

    4. Conclusion

    Using XML and XSLT for dynamic queries has at least the following advantages:

      1. The implementation method is simple and intuitive, avoiding the complexity of interaction between scripts and databases.
      2. You can easily support multiple types of documents that can be used by users, including HTML documents. Because XML documents are used to separate the content and representation of data, the difference between different users and documents is that they use different styles. I believe that with the continuous improvement and development of XML standardization, XML will have better application prospects in dynamic data processing.

    References:

      • Dong shaochun, Xu shijin, Lu xiancai, XML-based online course structure performance, display and query, Computer Application Research, 2001, Vol.8, 89-91.
      • Zhao shuliang, XML application research, computer science, 2001, Vol.28, 94-95.
    author profile

    Zhuo Qun, 99 graduate student from Computer Science Department of Sun Yat-sen University, the research direction is pattern recognition. Participated in the Sixth National Human-Computer Speech Communication Conference and was selected into the paper "some improvements to the fuzzy Gaussian Mixture Model-Based Speaker Recognition algorithm ". E-mail: zhuoqun@163.net

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.