Add XML header information after transform

mvamshi

New Member
I have an xml document which I transform, view in the browser and save to a directory. I would like to add a linked stylesheet to the saved version of the file. I've tried str_replace as below (might be incorrect usage) and also using xsl processing instruction.xsl processing instruction worked to a degree, if you view source in the browser, you would see the stylesheet link, however it would not save this information to the saved file!!All I want to do is take the raw xml file, transform it with the stylesheet, save it to a directory and append the xsl stylesheet to the header of the new file, so when the newly saved xml file is opened in the browser, the stylesheet is applied automatically. Hope this makes sense!!My code is below.\[code\]//write to the file$id = $_POST['id'];//xml id$path = 'xml/';//send to xml directory$filename = $path. $id . ".xml";$header = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8" ?><?xml-stylesheet type="text/xsl" href="http://stackoverflow.com/questions/foo.xsl"?>');$article->asXML($filename);//saving the original xml as new file with posted id$xml = new DOMDocument;$xml->load($filename);$xsl = new DOMDocument;$xsl->load('insert.xsl');$proc = new XSLTProcessor;$proc->importStyleSheet($xsl);echo $proc->transformToXML($xml);\[/code\]Thanks in advance!
 
Back
Top