Skip to content
Snippets Groups Projects
Commit 4b7e79f5 authored by Demian Katz's avatar Demian Katz
Browse files

Added parameter handling to XSLT processor.

parent 85da31c5
No related merge requests found
...@@ -42,12 +42,13 @@ class Processor ...@@ -42,12 +42,13 @@ class Processor
/** /**
* Perform an XSLT transformation and return the results. * Perform an XSLT transformation and return the results.
* *
* @param string $xslt Name of stylesheet (in application/xsl directory) * @param string $xslt Name of stylesheet (in application/xsl directory)
* @param string $xml XML to transform with stylesheet * @param string $xml XML to transform with stylesheet
* @param string $params Associative array of XSLT parameters
* *
* @return string Transformed XML * @return string Transformed XML
*/ */
public static function process($xslt, $xml) public static function process($xslt, $xml, $params = array())
{ {
$style = new DOMDocument(); $style = new DOMDocument();
// TODO: support local overrides // TODO: support local overrides
...@@ -56,6 +57,9 @@ class Processor ...@@ -56,6 +57,9 @@ class Processor
$xsl->importStyleSheet($style); $xsl->importStyleSheet($style);
$doc = new DOMDocument(); $doc = new DOMDocument();
if ($doc->loadXML($xml)) { if ($doc->loadXML($xml)) {
foreach ($params as $key => $value) {
$xsl->setParameter('', $key, $value);
}
return $xsl->transformToXML($doc); return $xsl->transformToXML($doc);
} }
return ''; return '';
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment