Link to home
Create AccountLog in
Avatar of IlpoHokkanen
IlpoHokkanen

asked on

PHP5 function to replace xslt_error() ?

I am trying to find out how to get xsl transform errors and xml errors in PHP5. I have used xslt_error() before, but since that is php4 function that has been depricated, I need something else.. I require assistance, I hope someone can help.
$xslt_parse = new XSLTProcessor();
$xslt_parse->importStyleSheet($xsl_obj);
if (false === ($transformed_xml = $xslt_parse->transformToXML($xml_obj)))
{
  throw new Exception("Unable to transform xml.");	
  //TODO: How can I know what went wrong with the transform ???	
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of aconrad
aconrad

also, an example is at
http://www.php.net/manual/en/function.libxml-get-errors.php
<?php
//this will output error
//Opening and ending tag mismatch: titles line 4 and title
 
libxml_use_internal_errors(true);
 
$xmlstr = <<< XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <titles>PHP: Behind the Parser</title>
 </movie>
</movies>
XML;
 
$doc = simplexml_load_string($xmlstr);
$xml = explode("\n", $xmlstr);
 
if (!$doc) {
    $errors = libxml_get_errors();
 
    foreach ($errors as $error) {
        echo display_xml_error($error, $xml);
    }
 
    libxml_clear_errors();
}
 
 
function display_xml_error($error, $xml)
{
    $return  = $xml[$error->line - 1] . "\n";
    $return .= str_repeat('-', $error->column) . "^\n";
 
    switch ($error->level) {
        case LIBXML_ERR_WARNING:
            $return .= "Warning $error->code: ";
            break;
         case LIBXML_ERR_ERROR:
            $return .= "Error $error->code: ";
            break;
        case LIBXML_ERR_FATAL:
            $return .= "Fatal Error $error->code: ";
            break;
    }
 
    $return .= trim($error->message) .
               "\n  Line: $error->line" .
               "\n  Column: $error->column";
 
    if ($error->file) {
        $return .= "\n  File: $error->file";
    }
 
    return "$return\n\n--------------------------------------------\n\n";
}
 
?>

Open in new window