Ability to apply XSLT to Template
This commit is contained in:
parent
029de3183a
commit
abbd288509
@ -75,6 +75,36 @@ class PHPWord_Template
|
|||||||
throw new PHPWord_Exception('Could not create temporary file with unique name in the default temporary directory.');
|
throw new PHPWord_Exception('Could not create temporary file with unique name in the default temporary directory.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Set a Template value
|
||||||
@ -134,4 +164,4 @@ class PHPWord_Template
|
|||||||
|
|
||||||
rename($this->_tempFileName, $strFilename);
|
rename($this->_tempFileName, $strFilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user