473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

XSL error handling in PHP5

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

Apr 18 '06 #1
2 3113
I solved this problem years ago:

1) Have a standard error handler which can be invoked using trigger_error();
I call mine 'errorHandler'.

2) Create an alternative error handler for XML/XSL processing in PHP 5. I
call mine 'XML_errorHandler'

function XML_errorHandler ($errno, $errstr, $errfile, $errline,
$errcontext)
// deal with errors from XML or XSL functions.
{
// pass these details to the standard error handler
errorHandler (E_USER_ERROR, $errstr, $errfile, $errline,
$errcontext);
} // XML_errorHandler

3) Just before performing and XML/XSL processing switch to the alternative
error handler:

set_error_handler('XML_errorHandler');

4) Don't forget to switch back again afterwards:

set_error_handler('errorHandler');

All this code can be downloaded from my website in my sample application at
http://www.tonymarston.net/php-mysql...plication.html

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
<al*******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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

Apr 19 '06 #2

Tony Marston wrote:
I solved this problem years ago:

1) Have a standard error handler which can be invoked using trigger_error();
I call mine 'errorHandler'.

2) Create an alternative error handler for XML/XSL processing in PHP 5. I
call mine 'XML_errorHandler'

function XML_errorHandler ($errno, $errstr, $errfile, $errline,
$errcontext)
// deal with errors from XML or XSL functions.
{
// pass these details to the standard error handler
errorHandler (E_USER_ERROR, $errstr, $errfile, $errline,
$errcontext);
} // XML_errorHandler

3) Just before performing and XML/XSL processing switch to the alternative
error handler:

set_error_handler('XML_errorHandler');

4) Don't forget to switch back again afterwards:

set_error_handler('errorHandler');

All this code can be downloaded from my website in my sample application at
http://www.tonymarston.net/php-mysql...plication.html

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org


thank you very match!
it`s cool way!
I`m tested it and find it very nice!

Apr 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chung Leong | last post by:
Help me here. I've become a bitconfused about how PHP4 deals with objects after reading this description of PHP5: "PHP's handling of objects has been completely rewritten, allowing for better...
11
by: neur0maniak | last post by:
Hi, I've been eager to try out PHP5, so I've dumped it on my little dev machine. It's running WinXP with IIS5. I've put the php-cgi.exe in the "mappings" page as I'm used to doing with PHP4....
0
by: Darek | last post by:
Hello, I'm trying to install PHP5. My configure is ../configure --with-apxs=/usr/local/sbin/apxs -- prefix=PREFIX=/usr/local/php5/ --with-mysql --disable-pear then make and make install ...
1
by: Mike | last post by:
Last weekend I decided to install Apache 2.0.53-win32-x86-no_ssl PHP 5.0.3 Smarty 2.6.7 MySQL essential-4.1.10-win32 I have Apache up (Port 80 blocked at the router and firewall!) and I have...
16
by: lawrence k | last post by:
I've never before written a PHP script to run on my home Ubuntu machine (though I've written dozens of PHP cron jobs for my web server), so I thought I'd start off with a very simple test: ...
4
by: MikeB | last post by:
I'm messing around with some sample code that I downloaded from a website (http://odnal.com/prosper-bid-sniper) that uses PHP objects and web services. When I upload it to my server, I get a...
5
by: simon m | last post by:
Hi All, I have a script sitting on my web server called auto_mail.php5. I would like this to be used two different ways. One way would be for a web form to call it as submit action on a form. I...
16
by: john6630 | last post by:
Coming from the .Net world, I am used to the try...catch...finally approach to error handling. And PHP 5 now supports this approach. But I am not clear what happens to unhandled errors/exceptioins?...
5
by: kellygreer1 | last post by:
I think I'm not quite understanding something about error handling in PHP5. I have written some PHP code to index the contents of C drive on a Windows machine. When it gets to certain special...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.