Hi mars, thanks for the piece of code i'm going to use it .
till now i used xslt_process() function only to transform my xml data
AS a WHOLE . that is i store in an $xml var a query from a database
and i have the xsl data on a file on the disk.
then
xslt_transform($xsl,$xml,$output)
print ($output) ;
send the transformed content to the browser.
this is a whole-approach.
QUESTION:
is there a streamline approach for sablotron functions in PHP ? like
the xml_parse() for expat ?
in your code below the xsl_run () is an whole-approach as well,
right ? but what if very big documents ?
apart from that, is it that the benefit of xsl_run() over xslt_process
() is that it makes possible to handle error messages like you did ?
> Pascal...
>
> I can't help you with the whitespace issues, but I recently wrote a
> simple error handler in PHP to write those pesky hidden Sablotron
> messages off to a log file (and coincidentally stop those msgtype
> warnings).
>
> Here's the relevant PHP source:
>
> <?php
>
> /* Figure out the base URI */
> $therealpath = $HTTP_SERVER_VARS["PATH_TRANSLATED"];
> $path_parts = pathinfo ($therealpath);
> $baseURI = $path_parts["dirname"];
>
> /* Open the log file at that base URI */
> $logfile = $baseURI . '/sablot.log';
> $XSLTerrorlog = fopen ($logfile, "w");
>
> /* Make a time stamp for the log file */
> $timearray = getdate();
> $timestamp = "Sablotron Runtime: " . $timearray["year"] . "-" .
> $timearray["mon"] . "-" . $timearray["mday"] . " " .
> $timearray["hours"] . ":" . $timearray["minutes"] . ":" .
> $timearray["seconds"] . "\n";
>
> /* Establish values to pass to Sablotron */
> $xsl = 'xsl-transform.xml';
> $xml = 'content.xml';
> $xslt_params["foo1"] = "foovalue1";
> $xslt_params["foo2"] = "foovalue2";
>
> /* Formats the $errors array with Tabs and CR's for text log file */
> function tabarraydata($value, $key) {
> global $XSLTerrorlog;
> fwrite ($XSLTerrorlog,"\t$key\t$value\n");
> }
>
> /* Writes Sablotron error info to log file */
> function xsl_error_handler($parser, $code, $level, $errors) {
> global $XSLTerrorlog, $timestamp;
>
> fwrite ($XSLTerrorlog,$timestamp);
> fwrite ($XSLTerrorlog,"Parser: $parser\n");
> fwrite ($XSLTerrorlog,"Code: $code\n");
> fwrite ($XSLTerrorlog,"Level: $level\n");
> fwrite ($XSLTerrorlog,"Messages: \n");
> array_walk ($errors, "tabarraydata");
> fwrite ($XSLTerrorlog,"\n");
> }
>
> /* Instantiate Sablotron */
> $theXSLTproc = xslt_create();
>
> /* Set the error handler for this instance (this is NOT in the PHP
> docs) */
> xslt_set_error_handler($theXSLTproc, "xsl_error_handler");
>
> /* Run the Transform with Sablotron */
> xslt_run ($theXSLTproc, $xsl, $xml, "arg:/_result", $xslt_params);
>
> /* Grab the transform's results */
> $result = xslt_fetch_result ($theXSLTproc);
>
> /* Write results to Response */
> echo $result;
>
> /* Clean it up */
> xslt_free($theXSLTproc);
> fclose ($XSLTerrorlog);
> ?>
>
> This codes works on my install of Apache 3.14/PHP 4.04pl1/Sablotron
0.51
> under Mac OS X/Darwin.
>
> - Mars
>
>
>