Transforming XML with XSLT and PHP
(Page 1 of 5 )
In this tutorial, Timothy shows you how to use XSLT to transform XML documents into HTML documents. Of course, the use of PHP XSLT functions are highlighted.
In one of my previous tutorials, Processing XML with PHP, I introduced you to the expat XML parser. The parser is sufficient for extracting information from an XML document and manipulating it in a simple event based manner. However, there may be times when it's desired to transform the XML document into a different format using XML StyLesheet Transforms (XSLT).
XSLT is essentially a series of templates and rules for XML. It processes a document by applying the template patterns according to the prescribed rules. XSLT can be used to generate pretty much any type of file from an XML document, such as .svg, .cvs, or .pdf. In this tutorial we will use XSLT to transform an XML document into an HTML document and use PHP’s XSLT functions to apply those rules.
The XSLT functions are not made available with a default PHP compilation. The Sablotron and expat libraries need to be available and PHP must be compiled with the --enable-xslt and --with-xslt-sablot options. More information, as well as links to obtain Sablotron and expat, are available at http://www.php.net/xslt.
Next: The XML Document >>
More Miscellaneous Articles
More By bluephoenix