您需要
compile PHP并支持它,并确保拥有所有必需的依赖项.请参阅
PHP Manual for XSLT中的相应章节.
This extension requires the libxml PHP extension. This means that passing in –enable-libxml is also required, although this is implicitly accomplished because libxml is enabled by default. This extension uses Sablotron and expat, which can both be found at » 07003. Binaries are provided as well as source. Enable by using the –with-xslt option with PHP 4.
On Unix, run configure with the –enable-xslt –with-xslt-sablot options. The Sablotron library should be installed somewhere your compiler can find it. Make sure you have the same libraries linked to the Sablotron library as those, which are linked with PHP. The configuration options: –with-expat-dir=DIR –with-iconv-dir=DIR are there to help you specify them. When asking for support, always mention these directives, and whether there are other versions of those libraries installed on your system somewhere. Naturally, provide all the version numbers.
$xml = new DOMDocument;
$xml->load('collection.xml');
$xsl = new DOMDocument;
$xsl->load('collection.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
transformToXML方法将返回已转换的文档或FALSE,因此您可以保留代码中的if / else.无论如何,升级代码应该是微不足道的.