protected function process_transform($form, $endpoint, $transform, $message, $as_string) { if (is_string($message)) { $document = new DOMDocument(); $document->loadXML($message); } else { if ($message instanceof DOMDocument) { $document = $message; } else { if ($message instanceof DOMNode) { $document = $message->ownerDocument; } else { I2CE::raiseError("Invalid object sent to transformer"); return false; } } } if (!$document instanceof DOMDocument) { I2CE::RaiseError("Could not load message as XML Doc"); return false; } if (array_key_exists($endpoint, $this->services[$form]) && is_array($this->services[$form][$endpoint]) && array_key_exists('transforms', $this->services[$form][$endpoint]) && is_array($this->services[$form][$endpoint]['transforms'])) { $transforms = $this->services[$form][$endpoint]['transforms']; } else { $transforms = array(); } $error_on_src_file = true; if (array_key_exists($transform, $transforms) && is_string($transforms[$transform])) { $transform_src = $transforms[$transform]; } else { $transform_src = '@' . $form . DIRECTORY_SEPARATOR . $endpoint . '_' . $transform . '.xsl'; $error_on_src_file = false; } if ($transform_src == '0') { //no outgoing message return ''; } if ($transform_src[0] == '@') { //it's a file. search for it. $file = substr($transform_src, 1); if (!($transform_file = I2CE::getFileSearch()->search('XSLTS', $file)) || !($transform_src = file_get_contents($transform_file))) { if ($error_on_src_file) { I2CE::raiseError("Invalid transform file at {$file} => {$transform_file}\n" . print_r(I2CE::getFileSearch()->getSearchPath('XSLTS'), true)); return false; } else { $transform_src = false; } } } if (!$transform_src) { if ($as_string) { return $document->saveXML(); } else { return $document; } } //try to do the transofmr $proc = new XSLTProcessor(); $xslDoc = new DOMDocument(); if (!$xslDoc->loadXML($transform_src)) { I2CE::raiseError("Invalid XSLT document form {$form}/{$endpoint}/{$transform}"); $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error, $xml); } return false; } if (!@$proc->importStylesheet($xslDoc)) { I2CE::raiseError("Could not import style sheet"); return false; } if (($out = @$proc->transformToXML($document)) === false) { I2CE::raiseError("Could not transform accoring to xsl"); return false; } I2CE::raiseError("Transformed to:\n{$out}"); if ($as_string) { return $out; } else { $out_doc = new DOMDocument(); if (!$out || !$out_doc->loadXML($out)) { return false; } return $out_doc; } }