1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?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);
- }
- }
|