Cheetah
ChXslTransform.php
Go to the documentation of this file.
1 <?php
2 
8 // class for XML/XSL tranformation
9 
10 define ('BXXSLTRANSFORM_FF', 4); // xml and xsl data in two files
11 define ('BXXSLTRANSFORM_FS', 2); // xml data in the file and xsl data in the string
12 define ('BXXSLTRANSFORM_SF', 1); // xml data in the string and xsl data in the file
13 define ('BXXSLTRANSFORM_SS', 0); // xml and xsl data in strings
14 
15 define ('BXXSLTRANSFORM_XML_FILE', 2); // xml file bit
16 define ('BXXSLTRANSFORM_XSL_FILE', 1); // xsl file bit
17 
19 {
20  var $_tmp_dir = "/tmp/";
21  var $_mode;
22  var $_xml;
23  var $_xsl;
24  var $_header = 'Content-Type: application/xml; charset=UTF-8';
25 
32  function __construct ($xml, $xsl, $mode)
33  {
34  $this->_mode = $mode;
35  $this->_xml = $xml;
36  $this->_xsl = $xsl;
37  }
38 
39  function process ()
40  {
41  global $gConf;
42 
43  if ('client' == $gConf['xsl_mode']) {
44  echo 'depricated'; exit;
45  }
46 
47  header ($this->_header);
48 
49  // xml: string, xsl: file
50  if ( !($this->_mode & BXXSLTRANSFORM_XML_FILE) && ($this->_mode & BXXSLTRANSFORM_XSL_FILE) ) {
51  $args = array(
52  '/_xml' => $this->_xml,
53  );
54 
55  validate_unicode ($this->_xml);
56 
57  if (((int)phpversion()) >= 5) {
58 
59  $xml = new DOMDocument();
60  if (!@$xml->loadXML($this->_xml)) {
61  $mk = new Mistake ();
62  $mk->log ("ChXslTransform::process - can not load xml:\n " . $this->_xml);
63  $mk->displayError ("[L[Site is unavailable]]");
64  }
65 
66  $xsl = new DomDocument();
67  $xsl->load($this->_xsl);
68 
69  $proc = new XsltProcessor();
70  $proc->importStyleSheet($xsl);
71  $res = $proc->transformToXML($xml);
72 
73  } else {
74 
75  if (function_exists('domxml_xslt_stylesheet_file')) {
76  $xmldoc = new DomDocument ($this->_xml);
77  $xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
78  $result = $xsldoc->process($xmldoc);
79  $res = $xsldoc->result_dump_mem($result);
80  } elseif (function_exists ('xslt_create')) {
81  $xh = xslt_create();
82  xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
83  $res = xslt_process ($xh, 'arg:/_xml', $this->_xsl, NULL, $args);
84  xslt_free($xh);
85  } else {
86  die('Server XSLT support is not enabled, try to use client XSL transformation http://your-domain/orca_folder/?xsl_mode=client');
87  }
88  }
89 
90  return $res;
91  }
92 
93  // xml: file, xsl: file
94  if ( ($this->_mode & BXXSLTRANSFORM_XML_FILE) && ($this->_mode & BXXSLTRANSFORM_XSL_FILE) ) {
95 
96  if (((int)phpversion()) >= 5) {
97  $xml = new DOMDocument();
98  $xml->load($this->_xml);
99 
100  $xsl = new DomDocument();
101  $xsl->load($this->_xsl);
102 
103  $proc = new XsltProcessor();
104  $proc->importStyleSheet($xsl);
105  $res = $proc->transformToXML($xml);
106  } else {
107  if (function_exists('domxml_xslt_stylesheet_file')) {
108  $xmldoc = new DomDocument ($this->_xml);
109  $xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
110  $result = $xsldoc->process($xmldoc);
111  $res = $xsldoc->result_dump_mem($result);
112  } elseif (function_exists ('xslt_create')) {
113  $xh = xslt_create();
114  $res = xslt_process ($xh, $this->_xml, $this->_xsl, NULL, $args);
115  xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
116  xslt_free($xh);
117  } else {
118  die('XSLT support is not enabled');
119  }
120  }
121  return $res;
122  //return `/opt/jre1.5.0_06/bin/java -jar /opt/saxon/saxon.jar -ds {$this->_xml} {$this->_xsl}`;
123  }
124 
125  return "<h1>not supported</h1>";
126  }
127 
128  function setHeader ($s)
129  {
130  $this->_header = $s;
131  }
132 
133 // private methods
134 
135  function _genFilename ()
136  {
137  list ($usec, $sec) = explode (' ', microtime());
138  srand ((float) $sec + ((float) $usec * 100000));
139  return $this->_tmp_dir . '/' . rand() . '_' . rand() . '.xml';
140  }
141 
142 }
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
php
BXXSLTRANSFORM_XML_FILE
const BXXSLTRANSFORM_XML_FILE
Definition: ChXslTransform.php:15
Mistake
Definition: Mistake.php:11
ChXslTransform\$_xml
$_xml
Definition: ChXslTransform.php:22
ChXslTransform\$_mode
$_mode
Definition: ChXslTransform.php:21
ChXslTransform\$_header
$_header
Definition: ChXslTransform.php:24
exit
exit
Definition: cart.php:21
ChXslTransform\setHeader
setHeader($s)
Definition: ChXslTransform.php:128
ChXslTransform\$_xsl
$_xsl
Definition: ChXslTransform.php:23
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChXslTransform
Definition: ChXslTransform.php:19
validate_unicode
validate_unicode(&$s)
Definition: util.inc.php:195
ChXslTransform\process
process()
Definition: ChXslTransform.php:39
ChXslTransform\$_tmp_dir
$_tmp_dir
Definition: ChXslTransform.php:20
$s
$s
Definition: embed.php:13
ChXslTransform\__construct
__construct($xml, $xsl, $mode)
Definition: ChXslTransform.php:32
BXXSLTRANSFORM_XSL_FILE
const BXXSLTRANSFORM_XSL_FILE
Definition: ChXslTransform.php:16
ChXslTransform\_genFilename
_genFilename()
Definition: ChXslTransform.php:135
$gConf
global $gConf
Definition: header.inc.php:8