I have successfully generated an xml file using dom in php dynamically, but I am unsure how to put CSS link in it.

I need the php code to link CSS with that automatically generated XML file.

1 Answers

ThW On Best Solutions

To link an CSS in XML you can use the xml-stylesheet processing instruction. Use the corresponding method on DOMDocument to create it and then append/insert it just like any other node.

$document = new DOMDocument();
    'xml-stylesheet', 'type="text/css" href="styles.css"'
echo $document->saveXML();


<?xml version="1.0"?> 
<?xml-stylesheet type="text/css" href="styles.css"?>