BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
PHP XML
PHP XSLT Function xslt_setopt
PHP XSLT Function xslt_process
PHP XSLT Function xslt_getopt
PHP XSLT Function xslt_free
PHP XSLT Function xslt_error
PHP XSLT Function xslt_create
PHP SimpleXML Function New_Doc
PHP SimpleXML Function Save
PHP SimpleXML Function load_string
PHP SimpleXML Function Load_File
PHP SimpleXML Function LoadXML
PHP SimpleXML Function Load
PHP SimpleXML Function Open_File
PHP SimpleXML Function xml_parser_create
PHP SimpleXML Create an XML Document
PHP XML RPC Function Server Call method
PHP XML RPC Parse Method Descriptions
PHP XML RPC Function ServerCreate
PHP XML RPC Function GetType
PHP XML RPC Function EncodeRequest
 
 

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :194

 

PHP XSLT Function xslt_set_error_handler

PHP Version: PHP 4 >= 4.0.4

Description

This function sets an error handler for the xslt processor. This is a most useful function to take care of any errors during transformation. Using this function user can take care error handling and display user friendly error messages.

Usage:

voidxslt_set_error_handler ( resource xh, mixed handler)

Set an error handler function for the XSLT processor given by xh, this function will be called whenever an error occurs in the XSLT transformation (this function is also called for notices).

The user function needs to accept four parameters: the XSLT processor, the error level, the error code and an array of messages. The function can be shown as: error_handler( resourcexh, interror_level, interror_code, array messages).

In my below example, I have used a xml file which is not well-formed.

Content of employee.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<employee>

            <employeename>test</employeename1>

            <employeeaddress>test123</employeeaddress>

            <SSN>12343456</SSN>

            <company>XYZ Corporation</company>

</employee>

Content of xsl file:

<?xml version='1.0'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

<head><title>XSLT in PHP</title></head>

<body>

     <xsl:for-each select="//employee">

          <BR><B>Employee Name:<xsl:value-of select="employeename"/></B></BR>

          <BR><B>Employee Address:<xsl:value-of select="employeeaddress"/></B></BR>

          <BR><B>SSN:<xsl:value-of select="SSN"/></B></BR>

          <BR><B>Company:<xsl:value-of select="company"/></B></BR>

     </xsl:for-each>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

PHP Code:

  <?php

$processor = xslt_create();

//set the error handler

xslt_set_error_handler($processor, "errorHandler");

//perform the transformation

$transformed = xslt_process($processor, 'employee.xml', 'employee.xsl');

//display the error messages. This line will not get executed because of error during transformation

echo $transformed;

//free the processor

xslt_free($processor);

//This is the xslt error handler. Just display the messages.

functionerrorHandler($handler, $errno, $level, $info)

{

  echo "<PRE>";

  var_dump(func_get_args());

  echo "</PRE>";

}

?>

Output

array(4) {
  [0]=>
  resource(2) of type (XSLT Processor)
  [1]=>
  int(3)
  [2]=>
  int(0)
  [3]=>
  array(6) {
    ["msgtype"]=>
    string(5) "error"
    ["code"]=>
    string(1) "2"
    ["module"]=>
    string(9) "Sablotron"
    ["URI"]=>
    string(58) "file:///C:/Program Files/Apache Group/Apache2/employee.xml"
    ["line"]=>
    string(1) "3"
    ["msg"]=>
    string(34) "XML parser error 7: mismatched tag"
  }
}

Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C
Sr. Software Engineer

View all Jobs (Add yours)
View all CV (Add yours)



cfxmasks
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses
conference calls


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP