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

Link to comment
Share on other sites

//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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.