20.12 Filtering All Output Through an XSL File


You want to filter all XML output through an XSL file and display it to the user .

Technique

Use the Sablotron XSL's output buffering tie-ins to transform your output:

 <?php xslt_output_begintransform('tst.xsl'); $doc = new_xmldoc('1.0'); $root = $doc->add_root('sites'); $site = $root->new_child('site', ''); $site->new_child('title', 'PHP.net'); $site->new_child('url', 'http://www.php.net'); $site->new_child('description', 'The homepage of PHP'); $site->new_child('keywords',                  'MySQL, PHP, Documentation, downloads, articles, books'); // XML output will be transformed by // tst.xsl print $doc->dumpmem(); xslt_output_endtransform(); ?> 

Comments

The Sablotron XSL module ties in to PHP's output buffering functions and enables you to transform all output sent to stdout through an XSL stylesheet given by the first argument to the xslt_output_begintransform() function. When you want to finish the output buffering, you can use the xslt_output_endtransform() function, which transforms all the data and outputs it to stdout .



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net