1 .xslt preliminary

xiaoxiao2021-03-14  189

XSL is also the so-called extensible style, which consists of three languages. These three languages ​​are responsible for converting XML documents to other formats. XML FO (XSL formatted object: XSL Formatting Objects) Describes the visual document format, and XPath accesses the specific part of the XML document. But XSLT (XSL Transformations) converts an XML document to the actual language in other formats.

The simplest application first involves two documents: XML documents that contain raw data and XSLT style forms used to convert the document. The XSLT processor applies the rules of the XSLT style form to the XML document to create new XHTML, WML, SVG, or almost any other third document in any XML format.

Multiple XSLT style forms can use a variety of formats to express a certain document. A single style form can also convert a variety of instances of a data type to a standard report format, and you only need to modify the style form to change these report modes. And XSLT can convert multiple instances of data into a variety of formats, not just about report format: It can be seen that XSLT is a data format of a system to another system (such as B2B transaction) data format. Powerful tool.

XSLT from the beginning

It takes time to carefully study the efficient method of using XSLT. Some of the learning content is very intuitive, and others may be very puzzled. However, once you are familiar with XSLT and XPath, you can use XSL quite quickly in the actual environment.

At first, you have to need an XSLT processor. With the rapid development of all kinds of technologies, the technical tools you use may make your project either documented. There are not many desktop XSLT prototype tools because most of these tools are for full-scale product systems. You must carefully consider how to support the XSLT specification.

Recently launched browsers, such as Internet Explorer 5.5, Netscape 6.1, and Mozilla, etc., all support XSLT processing features. They may be the simplest use tools in this regard, but it is quite lacking in their support. Also, the browser does not support real development tools, so it is useless when debugging the code. The XSLT format transformation is usually done on the server, so the browser can only be valid for the XML files containing the style table link.

Instant saxon is a command line for Windows systems, server-style XSLT simple processors. It implements basic file output and error message. Compared to the browser provides a more stable XSLT support. Although this tool is not a full-meaning development environment, INSTANT SAXON is still more than enough for the experimental tool.

XML SPY is a complete set of XML IDE that can be downloaded from the web. It uses Instant Saxon as its XSLT processor. This product is ideal for engineers who develop XML in the application environment, but you need to take some time to master this set of tools.

If these tools can be used for you, or you want yourself to create a complete set of applications, we will list some server-based XSLT processors at the end of this article.

Test example

The following example assumes the XSL processing tool and XML, and the XSL file is in a directory. In this example, we use an XML document to express a fast order, and we need to convert this document to readable HTML format.

Now copy the XML document and paste into a text editor, then save it as the Order.xml file. Similarly, copy the corresponding XSL document into files named ORDER.XSL. This XML file is linked to the XSL style form, so you can view the XML file in the appropriate browser, or use XML SPY to perform XSL Transform processing. Then open a MS-DOS command line window with Instant Sax, enter the directory where the file is located, type the saxon.exe order.xml order.xsl> Order.html command. The above command will output the converted HTML result as a file called ORDER.html so you can view the file through your own browser.

The results of the above examples are as follows: The title of the HTML page shows "Mike's order (fixed number 734)", the content is the list of foods, including prices, etc. The XSLT processor processes the XML file containing data and converts it to HTML output. The XSLT style form defines the HTML tag positioning that describes XML data, and the method is to use a processing instruction to form an XSLT language.

Although the XSLT processor usually accepts commands to use the corresponding style form processing, the XML document can indicate your default XSLT style form, which includes the following lines in the document:

Where my.xsl is the URL of the style form. The above code is a basic requirement for browser-based format.

转载请注明原文地址:https://www.9cbs.com/read-129388.html

New Post(0)