Jump to content

Using PHP to output Word using XSL.


daniel1982Au

Recommended Posts

I'm attemption to build a Word document with php.
An xml file is been populated with data. I then want to use an XSL(not xslt, if its possible) file to style the XML file (possibly in wordml)
and then spit out a word document.

What I am having trouble with is the XSL stylesheet itself, does anyone know if its actually possible to do it this way?

Does anyone have an example of an similar XSL file?

My example is not complete and I have omitted alot of error checking and some other stuff to keep it simple.

//Transformt the xml doc.
$xml = new DOMDocument;
$xml->load('project.xml');
$xsl = new DOMDocument;
$xsl->load('projectStyle.xsl');
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
$output = $proc->transformToXML($xml);

//fire it off to the clients browser so it can be ready for automatic download.
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename = ".$attributeType.".doc");
header("Content-Transfer-Encoding: binary");

//Spit out the word file.
readfile($output);

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/25885-using-php-to-output-word-using-xsl/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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