4 * Decorator/extender XSLT processor specifically for HTML documents.
6 class ConfigDoc_HTMLXSLTProcessor
10 * Instance of XSLTProcessor
12 protected $xsltProcessor;
14 public function __construct($proc = false) {
15 if ($proc === false) $proc = new XSLTProcessor();
16 $this->xsltProcessor
= $proc;
20 * @note Allows a string $xsl filename to be passed
22 public function importStylesheet($xsl) {
23 if (is_string($xsl)) {
25 $xsl = new DOMDocument();
26 $xsl->load($xsl_file);
28 return $this->xsltProcessor
->importStylesheet($xsl);
32 * Transforms an XML file into compatible XHTML based on the stylesheet
33 * @param $xml XML DOM tree, or string filename
34 * @return string HTML output
35 * @todo Rename to transformToXHTML, as transformToHTML is misleading
37 public function transformToHTML($xml) {
38 if (is_string($xml)) {
39 $dom = new DOMDocument();
44 $out = $this->xsltProcessor
->transformToXML($dom);
46 // fudges for HTML backwards compatibility
47 // assumes that document is XHTML
48 $out = str_replace('/>', ' />', $out); // <br /> not <br/>
49 $out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns
51 if (class_exists('Tidy')) {
55 'output-xhtml' => true,
59 $tidy->parseString($out, $config, 'utf8');
61 $out = (string) $tidy;
68 * Bulk sets parameters for the XSL stylesheet
69 * @param array $options Associative array of options to set
71 public function setParameters($options) {
72 foreach ($options as $name => $value) {
73 $this->xsltProcessor
->setParameter('', $name, $value);
78 * Forward any other calls to the XSLT processor
80 public function __call($name, $arguments) {
81 call_user_func_array(array($this->xsltProcessor
, $name), $arguments);