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)
16 if ($proc === false) $proc = new XSLTProcessor();
17 $this->xsltProcessor
= $proc;
21 * @note Allows a string $xsl filename to be passed
23 public function importStylesheet($xsl)
25 if (is_string($xsl)) {
27 $xsl = new DOMDocument();
28 $xsl->load($xsl_file);
30 return $this->xsltProcessor
->importStylesheet($xsl);
34 * Transforms an XML file into compatible XHTML based on the stylesheet
35 * @param $xml XML DOM tree, or string filename
36 * @return string HTML output
37 * @todo Rename to transformToXHTML, as transformToHTML is misleading
39 public function transformToHTML($xml)
41 if (is_string($xml)) {
42 $dom = new DOMDocument();
47 $out = $this->xsltProcessor
->transformToXML($dom);
49 // fudges for HTML backwards compatibility
50 // assumes that document is XHTML
51 $out = str_replace('/>', ' />', $out); // <br /> not <br/>
52 $out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns
54 if (class_exists('Tidy')) {
58 'output-xhtml' => true,
62 $tidy->parseString($out, $config, 'utf8');
64 $out = (string) $tidy;
71 * Bulk sets parameters for the XSL stylesheet
72 * @param array $options Associative array of options to set
74 public function setParameters($options)
76 foreach ($options as $name => $value) {
77 $this->xsltProcessor
->setParameter('', $name, $value);
82 * Forward any other calls to the XSLT processor
84 public function __call($name, $arguments)
86 call_user_func_array(array($this->xsltProcessor
, $name), $arguments);