Use PHP and XSLstylesheets to convert XML documents. PHP is a weapon used by many warriors in the Web development field because it is a very intuitive programming language with powerful functions and good cross-platform compatibility, it is also a free PHP weapon used by many warriors who are fighting in the Web development field, because it is a very intuitive programming language with powerful functions, good cross-platform compatibility, and it is free of charge. PHP shadows can be seen from small online stores to websites of large enterprises. One of the features of PHP is often overlooked, that is, the ability to work with XSL stylesheets to parse XML. Next let's take a look at how to set up an XSL parser in PHP and how to use this function. Example list A is A simple order document. we will enter this document into the XSL parser. In addition, the XSL stylesheet in list B will also be input into the XSL parser. Listing A: order. xml 9900234 1234
5.95
100 595.00 Super Widget Clamp 6234
22.00
10 220.00 Mighty Foobar Flange 9982
2.50
1000 2500.00 Deluxe Doohickie 3256
389.00
1 389.00 Muckalucket Bucket 1111 3704.00 07/07/2002 8876 Listing B: order. xsl Account SKU Description Price Quantity Subtotal In this example, we mainly use three XSL functions in PHP. First, we need to create an XSL Engine instance, then input all the documents to be input into this XSL engine for processing, and get the returned results. finally, disable the XSL engine when it is no longer needed. Create, process, and close an XSL process in memory. To facilitate the use of this XSL process in other XSL functions, PHP will provide us with a handle to this XSL process, rather than an object. The command to create this XSL engine is cmdt_create. The function returns a handle, as shown below: $ handle = effect_create (); to truly parse the XML document and enable XSLT to be processed, you must use the effect_process function in PHP. This function requires several different parameters. Here we use a very basic method to provide three parameters for effect_process. The first parameter is the handle of the XSL engine we created earlier. The second parameter is the name of the input XML document. The third parameter is the file name of the input XSL file. This function returns the processing result. The following is an example: $ return = effect_process ($ handle, $ xmlfile, $ Export file); the function we use is effect_free. This function is used to kill the XSL Engine instance in the memory and release the memory space. It only needs one parameter, that is, the handle of the XSL instance in the memory. The following is an example: using t_free ($ handle); The following describes how to use the above code snippets to process XML documents using XSL stylesheets. We use list A as our input XML document, and list B as our XSL input. List C is the complete PHP code in this example: Listing C: order. php "Quantity", "order" => "descending"); $ engine = effect_create (); $ output = effect_process ($ engine, $ xmlfile, $ your file, NULL, NULL, $ args); print $ output; effect_free ($ engine);?> Note that we have made some changes in the code. In XSL stylesheet, by specifying some parameters, we can change some regions, such as addresses. In this case, we need to specify that the items on the order should be arranged in descending order of quantity. We use the PHP array to store the parameter corresponding to our name, and then pass the name to the XSL engine through the effect_process function. Brian Schaffner is the deputy director of Fujitsu Consulting. He provides architecture, design, and development support for Fujitsu's technical consulting companies.
...