Jump to content

Help with PHP and XML (Convert my ASP Script to PHP)


mjs87

Recommended Posts

Basically I am trying to transform an XML document with XSL on the server. I have looked long and hard at how to do it in PHP and it seems quite complicated, however I have found the following ASP script that works and it seems pretty simple:

 

<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("document.xml"))

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("planstyle.xsl"))

'Transform file
Response.Write(xml.transformNode(xsl))
%> 

 

The only problem is that I need the transformation to be done in PHP, so could anyone point me in the right direction on how I could get a simple script like the above in php.

 

Many Thanks

//Load XML
$xml = new DOMDocument();
$xml->load(realpath("document.xml"));

//Load XSL
$xsl = new DOMDocument();
$xsl->load(realpath("planstyle.xsl"))); 

//Transform file
$xslt = new XSLTProcessor(); 

$xslt->importStylesheet($xsl); 

echo $xslt->transformToXML($xml); 

 

It's practically the same, except the transformation is done by a separate object. Not sure what you were looking at.

Thanks for the reply, which makes sense to me, I was looking at simpleXml and it seemed quite complicated. However with your solution I get the following error

 

Fatal error: Class 'XSLTProcessor' not found in blah\blah\index.php on line 11

 

Thanks for the help

If you're using the web host to test, and that's all you're interested in doing, then it's simply a matter of "don't". Test on a local development server. If this web host is going to host a web app that you want to XSLT in, then yes, it will need to be enabled on their server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.