Ability to apply XSLT to Template
This commit is contained in:
parent
029de3183a
commit
abbd288509
|
|
@ -76,6 +76,36 @@ class PHPWord_Template
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies XSL transformation to XML template.
|
||||
*
|
||||
* @param DOMDocument &$xslDOMDocument
|
||||
* @param string $xslOptionsURI
|
||||
* @param array $xslOptions
|
||||
*/
|
||||
public function applyXSLT(&$xslDOMDocument, $xslOptionsURI = '', $xslOptions = [])
|
||||
{
|
||||
$processor = new \XSLTProcessor();
|
||||
|
||||
$processor->importStylesheet($xslDOMDocument);
|
||||
|
||||
if ($processor->setParameter($xslOptionsURI, $xslOptions) === \FALSE) {
|
||||
throw new \Exception('Could not set values for the given XSL stylesheet parameters.');
|
||||
}
|
||||
|
||||
$xmlDOMDocument = new \DOMDocument();
|
||||
if ($xmlDOMDocument->loadXML($this->_documentXML) === \FALSE) {
|
||||
throw new \Exception('Could not create DOM document for the given XML template.');
|
||||
}
|
||||
|
||||
$xmlTransformed = $processor->transformToXml($xmlDOMDocument);
|
||||
if ($xmlTransformed === \FALSE) {
|
||||
throw new \Exception('Could not apply XSLT to the given DOM document.');
|
||||
}
|
||||
|
||||
$this->_documentXML = $xmlTransformed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a Template value
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue