From dfb1b695546854d0f97d57d5b0d5934fd434b81b Mon Sep 17 00:00:00 2001 From: Mehdi Achour Date: Fri, 30 Jul 2004 13:51:43 +0000 Subject: [PATCH] document xslt_set_option() better OO example for xslt_set_sax_handlers() using xslt_set_option() tell xslt_set_error_handler() users to use xslt_set_option() instead of passing an array with a reference to the object git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@164722 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../xslt/functions/xslt-set-error-handler.xml | 6 +-- reference/xslt/functions/xslt-set-object.xml | 49 +++++++++++++++-- .../xslt/functions/xslt-set-sax-handlers.xml | 53 ++++++++++--------- 3 files changed, 77 insertions(+), 31 deletions(-) diff --git a/reference/xslt/functions/xslt-set-error-handler.xml b/reference/xslt/functions/xslt-set-error-handler.xml index 3148923701..4f9a6f85cb 100644 --- a/reference/xslt/functions/xslt-set-error-handler.xml +++ b/reference/xslt/functions/xslt-set-error-handler.xml @@ -1,5 +1,5 @@ - + @@ -102,8 +102,8 @@ array(4) { - Instead of a function name, an array containing an object reference and - a method name can also be supplied. + See also xslt_set_object if you want to use an + object method as handler. diff --git a/reference/xslt/functions/xslt-set-object.xml b/reference/xslt/functions/xslt-set-object.xml index 6ab5ec70a2..121f7db95d 100755 --- a/reference/xslt/functions/xslt-set-object.xml +++ b/reference/xslt/functions/xslt-set-object.xml @@ -1,5 +1,5 @@ - + xslt_set_object @@ -11,12 +11,55 @@ Description intxslt_set_object - resourceparser + resourceprocessor objectobj + + This function allows to use the processor inside + an object and to resolve all callback functions + in it. + + + The callback functions can be declared with + xml_set_sax_handlers, + xslt_set_scheme_handlers or + xslt_set_error_handler and are assumed to be methods + of object. + + + + Using your own error handler as a method + +_xh = xslt_create(); + // Make $this object the callback resolver + xslt_set_object($this->_xh, $this); + + // Let's handle the errors + xslt_set_error_handler($this->_xh, "my_xslt_error_handler"); + } + + function my_xslt_error_handler($handler, $errno, $level, $info) + { + // for now, let's just see the arguments + var_dump(func_get_args()); + } +} + +?> +]]> + + + diff --git a/reference/xslt/functions/xslt-set-sax-handlers.xml b/reference/xslt/functions/xslt-set-sax-handlers.xml index b2ec3049f7..203c3c94aa 100644 --- a/reference/xslt/functions/xslt-set-sax-handlers.xml +++ b/reference/xslt/functions/xslt-set-sax-handlers.xml @@ -1,5 +1,5 @@ - + @@ -237,9 +237,8 @@ xslt_free($xh); - Every values of the handlers array is either a - string containing the function name, or an array in the following format: - array(&$obj, "method"). + You can also use xslt_set_object if you want to + implement your handlers in an object. @@ -252,6 +251,30 @@ class data_sax_handler { var $buffer, $tag, $attrs; + var $_xh; + + function data_sax_handler($xml, $xsl) + { + // our xslt resource + $this->_xh = xslt_create(); + + xslt_set_object($this->_xs, $this); + + // configure sax handlers + $handlers = array( + "document" => array('start_document', 'end_document'), + "element" => array('start_element', 'end_element'), + "character" => 'characters' + ); + + xslt_set_sax_handlers($this->_xh, $handlers); + + xslt_process($this->_xh, 'arg:/_xml', 'arg:/_xsl', NULL, array("/_xml"=>$xml, "/_xsl"=>$xsl)); + xslt_free($this->_xh); + + + } + function start_document() { // start reading the document @@ -287,27 +310,7 @@ class data_sax_handler { } -// our xsl handle -$xh = xslt_create(); - -$handler = new data_sax_handler(); -// configure sax handlers -$handlers = array( - "document" => array( - array(&$handler, 'start_document'), - array(&$handler, 'end_document') -), - "element" => array( - array(&$handler, 'start_element'), - array(&$handler, 'end_element') -), - "character" => array(&$handler, 'characters') -); - -xslt_set_sax_handlers($xh, $handlers); - -xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, array("/_xml"=>$xml, "/_xsl"=>$xsl)); -xslt_free($xh); +$exec = new data_sax_handler($xml, $xsl); ?> ]]>