mjs87 Posted November 21, 2009 Share Posted November 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/ Share on other sites More sharing options...
448191 Posted November 22, 2009 Share Posted November 22, 2009 //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. Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/#findComment-963108 Share on other sites More sharing options...
mjs87 Posted November 22, 2009 Author Share Posted November 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/#findComment-963241 Share on other sites More sharing options...
448191 Posted November 22, 2009 Share Posted November 22, 2009 You need the xsl extension enabled. How about RTFM eh? http://www.php.net/manual/en/xsl.installation.php Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/#findComment-963244 Share on other sites More sharing options...
mjs87 Posted November 22, 2009 Author Share Posted November 22, 2009 I am using a web host to test the program so will they have to install this? Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/#findComment-963248 Share on other sites More sharing options...
448191 Posted November 22, 2009 Share Posted November 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/#findComment-963251 Share on other sites More sharing options...
mjs87 Posted November 22, 2009 Author Share Posted November 22, 2009 ok cheers for all the help and advice. Quote Link to comment https://forums.phpfreaks.com/topic/182445-help-with-php-and-xml-convert-my-asp-script-to-php/#findComment-963256 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.