Example #1
0
 public static function transform($xml, $xsl, $output = self::XML, array $parameters = array(), array $register_functions = array())
 {
     self::flush();
     self::$lastXML = $xml;
     self::$lastXSL = $xsl;
     $result = null;
     libxml_use_internal_errors(true);
     if ($xml instanceof DOMDocument) {
         $XMLDoc = $xml;
     } else {
         $XMLDoc = new DOMDocument();
         $XMLDoc->loadXML($xml);
     }
     self::processLibXMLerrors(self::ERROR_XML);
     if ($xsl instanceof DOMDocument) {
         $XSLDoc = $xsl;
     } else {
         $XSLDoc = new DOMDocument();
         $XSLDoc->loadXML($xsl);
     }
     if (!self::hasErrors() && $XSLDoc instanceof DOMDocument && $XMLDoc instanceof DOMDocument) {
         $XSLProc = new XSLTProcessor();
         if (!empty($register_functions)) {
             $XSLProc->registerPHPFunctions($register_functions);
         }
         $XSLProc->importStyleSheet($XSLDoc);
         if (is_array($parameters) && !empty($parameters)) {
             $XSLProc->setParameter('', $parameters);
         }
         self::processLibXMLerrors(self::ERROR_XSL);
         if (!self::hasErrors()) {
             $result = $XSLProc->{'transformTo' . ($output == self::XML ? 'XML' : 'Doc')}($XMLDoc);
             self::processLibXMLerrors(self::ERROR_XML);
         }
     }
     return $result;
 }