예제 #1
0
 function process()
 {
     global $gConf;
     if ('client' == $gConf['xsl_mode']) {
         echo 'depricated';
         exit;
     }
     header($this->_header);
     // xml: string, xsl: file
     if (!($this->_mode & BXXSLTRANSFORM_XML_FILE) && $this->_mode & BXXSLTRANSFORM_XSL_FILE) {
         $args = array('/_xml' => $this->_xml);
         validate_unicode($this->_xml);
         if ((int) phpversion() >= 5) {
             $xml = new DOMDocument();
             if (!@$xml->loadXML($this->_xml)) {
                 $mk = new Mistake();
                 $mk->log("BxXslTransform::process - can not load xml:\n " . $this->_xml);
                 $mk->displayError("[L[Site is unavailable]]");
             }
             $xsl = new DomDocument();
             $xsl->load($this->_xsl);
             $proc = new XsltProcessor();
             $proc->importStyleSheet($xsl);
             $res = $proc->transformToXML($xml);
         } else {
             if (function_exists('domxml_xslt_stylesheet_file')) {
                 $xmldoc = new DomDocument($this->_xml);
                 $xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
                 $result = $xsldoc->process($xmldoc);
                 $res = $xsldoc->result_dump_mem($result);
             } elseif (function_exists('xslt_create')) {
                 $xh = xslt_create();
                 xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
                 $res = xslt_process($xh, 'arg:/_xml', $this->_xsl, NULL, $args);
                 xslt_free($xh);
             } else {
                 die('Server XSLT support is not enabled, try to use client XSL transformation http://your-domain/orca_folder/?xsl_mode=client');
             }
         }
         return $res;
     }
     // xml: file, xsl: file
     if ($this->_mode & BXXSLTRANSFORM_XML_FILE && $this->_mode & BXXSLTRANSFORM_XSL_FILE) {
         if ((int) phpversion() >= 5) {
             $xml = new DOMDocument();
             $xml->load($this->_xml);
             $xsl = new DomDocument();
             $xsl->load($this->_xsl);
             $proc = new XsltProcessor();
             $proc->importStyleSheet($xsl);
             $res = $proc->transformToXML($xml);
         } else {
             if (function_exists('domxml_xslt_stylesheet_file')) {
                 $xmldoc = new DomDocument($this->_xml);
                 $xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
                 $result = $xsldoc->process($xmldoc);
                 $res = $xsldoc->result_dump_mem($result);
             } elseif (function_exists('xslt_create')) {
                 $xh = xslt_create();
                 $res = xslt_process($xh, $this->_xml, $this->_xsl, NULL, $args);
                 xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
                 xslt_free($xh);
             } else {
                 die('XSLT support is not enabled');
             }
         }
         return $res;
         //return  `/opt/jre1.5.0_06/bin/java -jar /opt/saxon/saxon.jar -ds {$this->_xml} {$this->_xsl}`;
     }
     return "<h1>not supported</h1>";
 }
 function process($xml = null, $xsl = null, $param = array())
 {
     if ($xml) {
         $this->_xml = $xml;
     }
     if ($xsl) {
         $this->_xsl = $xsl;
     }
     $xml = trim($xml);
     $xsl = trim($xsl);
     if (!is_array($param)) {
         $param = array();
     }
     if (!_XSLT_AVAILABLE_) {
         return false;
     }
     //dont let process continue if no xsl functionality exists
     //DOMXML Extension
     if (_USING_DOMXML_XSLT_) {
         // Set up error handling
         $ehOLD = ini_set('html_errors', false);
         set_error_handler('trapXSLError');
         $xmldoc = domxml_open_mem($this->_xml, DOMXML_LOAD_PARSING, $xmlErrors);
         $xsldoc = domxml_xslt_stylesheet($this->_xsl);
         if (is_object($xmldoc) && is_object($xsldoc)) {
             $result = $xsldoc->process($xmldoc, $param);
             $result = $xsldoc->result_dump_mem($result);
         }
         // Restore error handling
         ini_set('html_errors', $ehOLD);
         restore_error_handler();
         //Process the errors while opening the XML
         while ($e = @array_shift($xmlErrors)) {
             $this->__error("2", $e['errormessage'], "xml", $e['line']);
         }
         //Use one of the custom error handlers to grab a list of processing errors
         $errors = trapXMLError(null, null, null, null, null, true);
         //Process the rest of the errors
         while ($error = @array_shift($errors)) {
             $this->__error($error['number'], $error['message'], $error['type'], $error['line']);
         }
         unset($xmldoc);
         unset($xsldoc);
         //PHP4/5 XSL Extension
     } else {
         $arguments = array('/_xml' => $this->_xml, '/_xsl' => $this->_xsl);
         $xsltproc = xslt_create();
         ##Make sure a bad document() call doesnt break the site
         if (PHP_VERSION < 5) {
             xslt_setopt($xsltproc, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
         }
         $result = @xslt_process($xsltproc, 'arg:/_xml', 'arg:/_xsl', null, $arguments, $param);
         if (PHP_VERSION >= 5) {
             //Use one of the custom error handlers to grab a list of processing errors
             $errors = trapXMLError(null, null, null, null, null, true);
             while ($error = @array_shift($errors)) {
                 $this->__error($error['number'], $error['message'], $error['type'], $error['line']);
             }
         } else {
             if (!$result && xslt_errno($xsltproc) > 0) {
                 $this->__error(xslt_errno($xsltproc), xslt_error($xsltproc));
             }
         }
         xslt_free($xsltproc);
     }
     return $result;
 }