PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / extras / ConfigDoc / HTMLXSLTProcessor.php
blob1cfec5d76274848479ef69678b734f847a9a56c0
1 <?php
3 /**
4 * Decorator/extender XSLT processor specifically for HTML documents.
5 */
6 class ConfigDoc_HTMLXSLTProcessor
9 /**
10 * Instance of XSLTProcessor
12 protected $xsltProcessor;
14 public function __construct($proc = false)
16 if ($proc === false) $proc = new XSLTProcessor();
17 $this->xsltProcessor = $proc;
20 /**
21 * @note Allows a string $xsl filename to be passed
23 public function importStylesheet($xsl)
25 if (is_string($xsl)) {
26 $xsl_file = $xsl;
27 $xsl = new DOMDocument();
28 $xsl->load($xsl_file);
30 return $this->xsltProcessor->importStylesheet($xsl);
33 /**
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();
43 $dom->load($xml);
44 } else {
45 $dom = $xml;
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')) {
55 // cleanup output
56 $config = array(
57 'indent' => true,
58 'output-xhtml' => true,
59 'wrap' => 80
61 $tidy = new Tidy;
62 $tidy->parseString($out, $config, 'utf8');
63 $tidy->cleanRepair();
64 $out = (string) $tidy;
67 return $out;
70 /**
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);
81 /**
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);
91 // vim: et sw=4 sts=4