ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
HTMLXSLTProcessor.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
12  protected $xsltProcessor;
13 
14  public function __construct($proc = false)
15  {
16  if ($proc === false) $proc = new XSLTProcessor();
17  $this->xsltProcessor = $proc;
18  }
19 
23  public function importStylesheet($xsl)
24  {
25  if (is_string($xsl)) {
26  $xsl_file = $xsl;
27  $xsl = new DOMDocument();
28  $xsl->load($xsl_file);
29  }
30  return $this->xsltProcessor->importStylesheet($xsl);
31  }
32 
39  public function transformToHTML($xml)
40  {
41  if (is_string($xml)) {
42  $dom = new DOMDocument();
43  $dom->load($xml);
44  } else {
45  $dom = $xml;
46  }
47  $out = $this->xsltProcessor->transformToXML($dom);
48 
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
53 
54  if (class_exists('Tidy')) {
55  // cleanup output
56  $config = array(
57  'indent' => true,
58  'output-xhtml' => true,
59  'wrap' => 80
60  );
61  $tidy = new Tidy;
62  $tidy->parseString($out, $config, 'utf8');
63  $tidy->cleanRepair();
64  $out = (string) $tidy;
65  }
66 
67  return $out;
68  }
69 
74  public function setParameters($options)
75  {
76  foreach ($options as $name => $value) {
77  $this->xsltProcessor->setParameter('', $name, $value);
78  }
79  }
80 
84  public function __call($name, $arguments)
85  {
86  call_user_func_array(array($this->xsltProcessor, $name), $arguments);
87  }
88 
89 }
90 
91 // vim: et sw=4 sts=4
Decorator/extender XSLT processor specifically for HTML documents.
Add rich text string
The name of the decorator.
transformToHTML($xml)
Transforms an XML file into compatible XHTML based on the stylesheet.
if(!is_array($argv)) $options
__call($name, $arguments)
Forward any other calls to the XSLT processor.
$xsltProcessor
Instance of XSLTProcessor.
Create styles array
The data for the language used.
setParameters($options)
Bulk sets parameters for the XSL stylesheet.