PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Is there a way to transform XML with XSLT on the server using PHP? I'm using a free web tutorial (you get what you pay for) and it's lacking to say the least. I've searched Google and tried a variety of solutions that all fail with fatal errors. The ASP code given for XML to XSLT transformation on the server is below:
<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("cdcatalog.xml"))
'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("cdcatalog.xsl"))
'Transform file
Response.Write(xml.transformNode(xsl))
%>
I'd be really grateful if someone could point me to a resource for XML with XSLT creation on the server with PHP. Thanks in advance for any help/tips/pointers
<?php
// LoadXML
$xml = new DomDocument;
$xml->load('cdcatalog.xml');
// Load XSL
$xsl = new DomDocument;
$xsl->load('cdcatalog.xsl');
// Transform file
$xp = new XsltProcessor();
$xp->importStylesheet($xsl);
echo $xp->transformToXML($xml);
?>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
st89 wrote:Is there a way to transform XML with XSLT on the server using PHP? I'm using a free web tutorial (you get what you pay for) and it's lacking to say the least. I've searched Google and tried a variety of solutions that all fail with fatal errors. The ASP code given for XML to XSLT transformation on the server is below:
<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("cdcatalog.xml"))
'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("cdcatalog.xsl"))
'Transform file
Response.Write(xml.transformNode(xsl))
%>
I'd be really grateful if someone could point me to a resource for XML with XSLT creation on the server with PHP. Thanks in advance for any help/tips/pointers
After more Googling, I found an answer that works. It turns out my previous failed attempts were due to using XSLT-related functions which only work in PHP4. For anyone reading this post, the following solution ONLY works in PHP5: