| PHP5 and XSLT | | Print | |
With the improved XML handling in PHP5, PHP4 modules like DOM XML and XSLT have been rendered obsolete, or at least deprecated. In PHP5, XSLT transformations are incorporated more cleanly into the features of its XML, DOM, and XSL extensions.
Because of this, the amount of flexibility available to PHP developers in working with XML, XSL, and HTML files in PHP5 is greatly increased; all of these separate file types are manipulated with the same, more generalized toolkit.
Sample Transformation Using PHP5
The PHP file shown in demonstrates the simplest way to perform an XSLT transformation on the sample files shown in and using the PHP5 DOM, XML, and XSLT extensions.
Listing 9.6. Sample Transformation File test-php5.php
1 <?php
2
3 $path_xml = "freedomland.xml";
4 $path_style = "forest.xsl";
5
6 $xml_obj = new DomDocument;
7 $xsl_obj = new DomDocument;
8
9 if (!$xml_obj->load($path_xml)) {
10 echo "Error! Unable to open " . $path_xml . "!\n";
11 exit;
12 }
13
14 if (!$xsl_obj->load($path_style)) {
15 echo "Error! Unable to open " . $path_style . "!\n";
16 exit;
17 }
18
19 $xslt_parse = new xsltprocessor;
20
21 $xslt_parse->importStyleSheet($xsl_obj);
22
23 echo $xslt_parse->transformToXML($xml_obj);
24
25 ?>
Although this document is simple enough that many PHP users will understand it with little or no trouble, a brief walk-through will clarify its flow for those less familiar with PHP scripts.
| Users' Comments (0) |
|
No comment posted






