dilithiumtoys_dot_com
asked on
How do I dump the xml I retrieve using PHP FUNCTION DOMXPATH::QUERY?
Hi,
I am trying to extract xml from a file and pass it to the xslt parser but its not working. How do I get the attached code to work?
I need to extract the products node and its children to pass to the stylesheet.
Thanks
I am trying to extract xml from a file and pass it to the xslt parser but its not working. How do I get the attached code to work?
I need to extract the products node and its children to pass to the stylesheet.
Thanks
<config>
<top40>
<products>
<product>
...
</product>
</products>
</config>
<?php
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load('xsl/products.xsl');
$xsl->importStyleSheet($doc);
$doc->load('xml/config.xml');
$xpath = new DOMXPath($doc);
$p = $doc->getElementsByTagName('top40')->item(0);
$x = $xpath->query('*',$p);
$data = $xsl->transformToXML($x);
echo $data;
?>
It doesn't like your XML. I notice that your sample data does not start with the usual header
<?xml version="1.0"?>
<?xml version="1.0"?>
Also, is there a reason why you are using DOM rather than SimpleXML? Are you on PHP4?
ASKER
I am generating the XML from SQL Server, I am sure I can return a declaration, if I can find out the method. May I transform documents to html using SimpleXML? I am using PHP 5.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did not work.
What worked was a mixture of simplexml extraction and saving as xml being passed to DOM and XSLTPROCESSOR.
What worked was a mixture of simplexml extraction and saving as xml being passed to DOM and XSLTPROCESSOR.
ASKER
Partially correct. I figured out my own answer
I didn't want to suggest SimpleXML as it seems that those using DOM either don't like SimpleXML or have requirements beyond its needs. Still I'm glad that you got it sorted out.
Cheers!
Cheers!
ASKER
Warning: XSLTProcessor::transformTo