Приглашаем посетить
Литература 20 век (20v-euro-lit.niv.ru)

Transforming XML with XSL and PHP 4

Previous
Table of Contents
Next

Transforming XML with XSL and PHP 4

$result = $xslt->process($dom);
echo $xslt->result_dump_mem($result);


To use XSL Transformations (XSLT) with PHP, you again have to decide first which PHP version to use. If it's PHP 4, you have to use extension=php_xslt.dll in php.ini (Windows), or install Sablotron from http://www.gingerall.com/and use the configuration switches enable-xslt with-xslt-sablot (for other systems).

Using XSLT with PHP 4 (xslt4.php)
<?php
  $dom = domxml_open_mem(file_get_contents('quotes.xml'));
  $xslt = domxml_xslt_stylesheet(
file_get_contents('quotes.xsl'));
  $result = $xslt->process($dom);
  echo $xslt->result_dump_mem($result);
?>

Doing the transformation is a number of four easy steps: Load the XML; load the XSLT; execute the transformation; and, finally, save the result. The preceding phrase contains the code for these steps; the file quotes.xsl in the download repository contains markup that transforms the quotes' XML into the well-known HTML bulleted list.


Previous
Table of Contents
Next