Re: PHP-sablotron

From: Date: Fri, 01 Sep 2000 14:05:52 +0000
Subject: Re: PHP-sablotron
References: 1 2 3 4 5 6  Groups: php.dev 
Request: Send a blank email to php-dev+get-31571@lists.php.net to get a copy of this message
Sterling Hughes wrote: > Great, > > Lets work on this! > > I'm in GMT -5 (Ny, US) but I've actually been switching timezones lately because > of all the work I've had to do, now I exist in my own special timezone called > the "I'll be awake no matter when you send me an e-mail timezone" :-). I > luckily just finished the last of all the major work this morning and slept for > the entire day (scary). > > Lets open up the conversation on this module right away, I think the first thing > to discuss would be the PHP API, this is what I'm envisioning for an API: > > 1) Hook it into the output buffering support so someone could do something > like: > > <?php > xslt_output_transform("somefile.xsl"); > > // All output would then be filtered through the style sheet > xslt_output_endtransform(); > > ?> > This would be very nice indeed, didn't think of it yet, but maybe we can start with the basic API, like the one below. > > 2) Lets also have the basics =-): > > int xslt_transform(string xsl_uri, string transform_uri, string result_uri[, > array params[, array buffers[, string result]]]) > Transform an xslt file > > <?php > if (xslt_transform($template, $datafile, 'arg:/result', 0, 0, &$result)) { > echo "The results of the transformation: $result"; > } > ?> Is the "arg:/result" systax used somewhere yet in an extension? I did never encounter it. I wonder if it's neccesairy to makes this call so difficult, maybe the _process call would suffice. Why would you want the other parameters exactly? > > > int xslt_process(string xsl, string data, string result) > Transform data and place it result: > > <?php > if (xslt_process($xsl, $data, &$result)) { > echo "The result of transformation: $result"; > } > ?> > This one looks neat too. > > 3) And finally, Lets have that nice little resource management api > > resource xslt_create(void) > Create a new xslt_processor > > <?php > $xh = xslt_create(); > > if (xslt_run($xh, 'test.xsl', 'test')) { > $data = xslt_fetch_result ($xh); > } > > xslt_free($xh); > ?> > > int xslt_run (resource xslt_handle, string xsl_file, string data_file[, string > result[, array params[, array buffers]]]) > Parse a xsl file with data_file Same comments as for xslt_transform here... > > > <?php > > $xh = xslt_create(); > > $buffers = array(xsl_file => 'test.xsl', > data_file => 'test'); Wht do you want this? > > > $ret = xslt_run($xh, 'arg:/xsl_file', 'arg:/data_file', > 'arg:/something', 0, > $buffers); > if ($ret) { > $data = xslt_fetch_result ($xh, 'arg:/something'); > } > xslt_free($xh); > ?> > > int xslt_free(resource xslt_handler) > Free a xslt_handler > > See above examples. > > > string xslt_error(resource xslt_handle) > Get an error string with the last error on the given handler. > > <?php > $xh = xslt_create(); > print xslt_error($xh); > xslt_free($xh); > ?> Looks like handy to me. > > > int xslt_log(resource xslt_handle, string filename[, int errorlevel]) > Log Sablot messages > > <?php > $xh = xslt_create(); > xslt_log($xh, "/www/logs/error_log"); > > if (!xslt_run($xh, $xsl, $datafile)) > print "Error Logged"; > This one too. > > int xslt_register_sax_handlers(resource xslt_handle, array handlers) > Register SAX handlers for event based parsing. > > <?php > function StartDoc () > { > print "Document Started"; > } > > function EndDoc () > { > print "Document Finished"; > } > > $handlers = array("Document" => > array("StartDoc", "EndDoc")); > > $xh = xslt_create(); > xslt_register_sax_handlers($xh, $handlers); > > if (xslt_run($xh, 'test.xsl', 'test')) { > $data = xslt_fetch_result ($xh); > } > xslt_free($xh); > ?> > I didn;t look at the SAX interface yet. I'll have a look at it, but it seems useful for me too. > > int xslt_set_docInfo_handler(resource xslt_handle, string handler) > Set the document information handler. > > <?php > > function DocumentInfo($content_type, $encoding) > { > print "This document has a content type of $content_type\n"; > print "and an Encoding of $encoding"; > } > > $handlers = array("Document" => > array("StartDoc", "EndDoc")); > > $xh = xslt_create(); > xslt_register_sax_handlers($xh, $handlers); > > if (xslt_run($xh, 'test.xsl', 'test')) { > $data = xslt_fetch_result ($xh); > } > xslt_free($xh); > ?> > > Comments? Of course :-) > > > Also I took a look at the source code of the existing sablot code (for > integration with PHP), and I don't really like the implementation too much (it > works, but its just not my cup of tea). Its seems too hard to extend and work > upon, and a little to complex for the task it is achieving and it doesn't have > the advanced features, perhaps we might have to write this thing from the ground > up either way :-). No big deal :-) I am not very experienced with extension writing, but I think we're able to create this kick-ass extension. Derick

« previous php.dev (#31571) next »