XSL error handling in PHP5
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

XSL error handling in PHP5

From: <al3x4nder@gmail.com>
Date: Tue Apr 18 2006 - 18:37:56 CEST

I`m need hanling XSLT errors in my script,
before I`m use Sablotron, that has nice
interface for it:
------------8<------------------
function ProduceXHTML($xml, $xsl){
        $xh = xslt_create();
        xslt_set_encoding ($xh, CODE_PAGE);
        $arguments = array('/_xml' => $xml, '/_xsl' => $xsl);
        $result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL,
$arguments);
        $this->error = (int)xslt_errno($xh);
        if($this->error){
                $errorMessage = sprintf("Cannot process XSLT document
[code %d]: %s",
xslt_errno($xh), xslt_error($xh));
                $this->AddErrorMessage(5, $errorMessage);
        }

        xslt_free($xh);
}

------------8<------------------

but now I`m ported my project
in PHP5 and use XSLlib like this:

------------8<------------------
function ProduceXHTML($xsltemplate){
        $xh = new XSLTProcessor();
        $xml = new DOMDocument();
        $xsl = new DOMDocument();

        $xsl->loadXML($this->LoadXSLT(TEMPLATES_ROOT.$xsltemplate));
        $xml->loadXML($this->xml);

        $xh->importStyleSheet($xsl);
        $xhtml=$xh->transformToXML($xml);

        if($this->IsDebug()){
                header('Content-type: text/xml');
                die($this->xml);
        }
        if ($xhtml) {
                $xhtml = str_replace("&amp;", "&", $xhtml);
                echo $xhtml;
        } else {
                /* commented, because PHPv5 used
                printf("Cannot process XSLT document [code %d]: %s",
xslt_errno($xh), xslt_error($xh));
                */
                return false; // invalid XSL
        }
        unset($xh);

}
------------8<------------------
anybody know how I can track errors now?

thanks and sorry for my English
Received on Mon May 1 02:58:58 2006