|
- <?php
-
-
- class ConfigDoc_HTMLXSLTProcessor
- {
-
-
-
- protected $xsltProcessor;
-
- public function __construct($proc = false)
- {
- if ($proc === false) $proc = new XSLTProcessor();
- $this->xsltProcessor = $proc;
- }
-
-
-
- public function importStylesheet($xsl)
- {
- if (is_string($xsl)) {
- $xsl_file = $xsl;
- $xsl = new DOMDocument();
- $xsl->load($xsl_file);
- }
- return $this->xsltProcessor->importStylesheet($xsl);
- }
-
-
-
- public function transformToHTML($xml)
- {
- if (is_string($xml)) {
- $dom = new DOMDocument();
- $dom->load($xml);
- } else {
- $dom = $xml;
- }
- $out = $this->xsltProcessor->transformToXML($dom);
-
-
-
- $out = str_replace('/>', ' />', $out);
- $out = str_replace(' xmlns=""', '', $out);
-
- if (class_exists('Tidy')) {
-
- $config = array(
- 'indent' => true,
- 'output-xhtml' => true,
- 'wrap' => 80
- );
- $tidy = new Tidy;
- $tidy->parseString($out, $config, 'utf8');
- $tidy->cleanRepair();
- $out = (string) $tidy;
- }
-
- return $out;
- }
-
-
-
- public function setParameters($options)
- {
- foreach ($options as $name => $value) {
- $this->xsltProcessor->setParameter('', $name, $value);
- }
- }
-
-
-
- public function __call($name, $arguments)
- {
- call_user_func_array(array($this->xsltProcessor, $name), $arguments);
- }
-
- }
-
|