Ability to apply XSLT to Template
This commit is contained in:
Roman Syroeshko 2014-01-01 06:28:10 -08:00
parent 029de3183a
commit abbd288509
1 changed files with 31 additions and 1 deletions

View File

@ -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
*