I am trying to get XSLT to work in PHP 5.1.1.
running phpinfo.php confirms .. dom, xml, and xsl extensions are all enabled (any other extensions needed for XSLT processing?)
.......................
Trying the examples directly from here .. Zend - XML in PHP5 - XSLT
articles.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<articles>
<item>
<title>PHP Weekly: Issue # 172</title>
<link>http://www.zend.com/zend/week/week172.php</link>
</item>
<item>
<title>Tutorial: Develop rock-solid code in PHP: Part three</title>
<link>http://www.zend.com/zend/tut/tut-hatwar3.php</link>
</item>
</articles>
articles.xsl
<?xml version=1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="titles" />
<xsl:template match="/articles">
<h2><xsl:value-of select="$titles" /></h2>
<xsl:for-each select=".//title">
<h3><xsl:value-of select="." /></h3>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
articles.php
<?php
/* load the xml file and stylesheet as domdocuments */
$xsl = new DomDocument();
$xsl->load("articles.xsl");
$inputdom = new DomDocument();
$inputdom->load("articles.xml");
/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
$proc->setParameter(null, "titles", "Titles");
/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
?>
I am seeing this list of errors .. (long filepaths snipped out, all three files located in same folder) ..
-
Warning: DOMDocument::load() [function.load]: String not started expecting ' or " in file:///C%3A/<snipped path>/articles.xsl, line: 1 in C:<snipped path>\articles.php on line 5
-
Warning: DOMDocument::load() [function.load]: Malformed declaration expecting version in file:///C%3A/<snipped path>/articles.xsl, line: 1 in C:<snipped path>\articles.php on line 5
-
Warning: DOMDocument::load() [function.load]: Blank needed here in file:///C%3A/<snipped path>/articles.xsl, line: 1 in C:<snipped path>\articles.php on line 5
-
Warning: DOMDocument::load() [function.load]: parsing XML declaration: '?>' expected in file:///C%3A/<snipped path>/articles.xsl, line: 1 in C:<snipped path>\articles.php on line 5
-
Warning: XSLTProcessor::importStylesheet() [function.importStylesheet]: compilation error in C:<snipped path>\articles.php on line 12
-
Warning: XSLTProcessor::importStylesheet() [function.importStylesheet]: xsltParseStylesheetProcess : empty stylesheet in C:<snipped path>\articles.php on line 12
-
Warning: XSLTProcessor::transformToDoc() [function.transformToDoc]: No stylesheet associated to this object in C:<snipped path>\articles.php on line 16
-
Fatal error: Call to a member function saveXML() on a non-object in C:<snipped path>\articles.php on line 17
...
What am I missing in my configuration?