Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

PHP5 and XSLT
 
Article Index
PHP5 and XSLT
Page 2
Page 3

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.


Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Naruto 3
Statistic


Last Post

 
Top! Top!