3
votes

for reasons beyond my control, I will get an XML file, and an XSLT file that can convert the XML file to either SQL code or to an error.

Lets just assume for now that we can trust the one providing the XML file not to include dangerous constructs in the XML...

I do not even know if I should use SimpleXML, XMLWriter, DOMDocument or something else. Also, should I use XSLTProcessor or something else?

What is the best way to implement this in PHP?

Thanks,

1

1 Answers

1
votes

If I've understood your question, and xmldata and stylesheet are provided, you can simply transform it like this:

$data = new DOMDocument();
$data->loadXML('<yourxmldata />';

$stylesheet = new DOMDocument();
$stylesheet->loadXML('<yourxslstylesheet/>');

$processor = new XSLTProcessor(); 
$processor->importStylesheet($stylesheet);
var_dump($processor->transformToXML($data));