Re: [PHP-XML-DEV] XSL in PHP5

[email protected] ("Rob Richards")
Newsgroups php.xml.dev
Message-ID <[email protected]>
Example is a little longer as it also includes some of the DOM functionality

Honza Skypala wrote in message
> I downloaded PHP 5 beta and I see there is a completely new way of XSL
> support. "xslt" extension is gone, instead we have "xsl" extension. I
> enabled the extension in php.ini file, but - I down know how to work with
> it. Can anybody please give me an example, 10 lines of code, that use the
> new extension? Please...


<?php
// create new xsltprocessor
$proc = new xsltprocessor();
// create new domDocument
$dom = new domDocument;
// create new domDocument
$dom2 = new domDocument;

// load domDocument from string
$dom2->loadxml('<?xml version="1.0" encoding="UTF-8"?><root>hello
world</root>');
// load domDocument from string
$dom->loadxml('<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="root"/>
<p/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>');

// import stylesheet from domDocument
$proc->import_stylesheet($dom);

// following are 3 ways to output the transformation
// write transformation output to a file (returns # bytes written)
print "Wrote: ".$proc->transform_to_uri($dom2, 'mystylesheet.txt')."\n\n";
// transformation output to a string (returns string)
print $proc->transform_to_xml($dom2)."\n\n";
// create domDocument from transformation (returns domDocument)
$result = $proc->transform_to_doc($dom2);
// output domDocument xml to string
print $result->savexml();
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.