Hi,

I am using php >4.1, with Sablotron.

I have both an xml and xsl file, and use sablotron to output html. But the
php expressions inside these files are not evaluated (i.e. left out in the
html-file)

How can they be evaluated for sure?

(most examples use sablotron with php4.0 and are therefore not of much
use...)



Here is what I have:

index.php:



PHP:------------------------------------------------------------------------
--------

<?php

// the files
$path = "/www/files_xml/";
$xmlfilename = $path . "file.xml";
$xslfilename = $path . "file.xsl";


// Allocate a new XSLT processor
$xslthandler = xslt_create() or die("No XSLT-handler available. Aborted.");


// set Processing Instruction handler to process()
// void xslt_set_sax_handlers ( resource processor, array handlers)
xslt_set_sax_handlers($xslthandler, array('pi'=>'PIHandler'));


// process the two files to get the desired output
$result = xslt_process($xslthandler, $xmlfilename, $xslfilename);
if ($result) {
  echo $result;
}
else {
  print "Sorry, \$xmlfile could not be transformed by \$xslfile into";
  print " the \$result variable. Reason: " . xslt_error($xslthandler);
  print ". Error code: " . xslt_errno($xslthandler);
}


// free the resources occupied by the xslthandler
xslt_free($xslthandler);


// processing instruction handler
function PIHandler($parser, $data, $target) {
  echo $data; // not working...
  switch (strtolower($target)) {
    case "php":
      eval("?>$data"); // not working...
      echo Date("Y"); // blah...
      break;
  }
}

?>

----------------------------------------------------------------------------
----


processing instruction handler isn't working...
$target contains 'php' when found an pi. But the $data does contains 'blah
blah' (no data). Further it does process the code inside the pihandler, but
I still can't pass php code to it.

(in php4.0 the arguments were like in: function PIHandler($parser, $target,
$data), I changed the order, so that $target contains 'php' when an pi is
encountered)
----------------

The xml file contains sometimes pieces of php code like:

PHP:------------------------------------------------------------------------
--------

<?php
  print "Hi!;
 ?>

----------------------------------------------------------------------------
----


------


The xsl-file contains a piece like:


PHP:------------------------------------------------------------------------
--------
<xsl:template match="processing-instruction('php')">
  hello
  <xsl:processing-instruction name="php">
   echo "hello";
   <!-- <xsl:value-of select="."/> -->
  </xsl:processing-instruction>
 </xsl:template>

----------------------------------------------------------------------------
----


But nothing seems to work...

------

It's really frustrating: I mean, I just want to evaluate some php code
inside the xml and xsl files. What's the big deal? Why should this be so
complicated? Please help.




Jerome wrote:

"if you us ob_*() functions, instead of writing HTML pages with php tags
inserted, you can write XML pages with PHP tags inserted.  then after you're
done, you can pass the contents of the output buffer to an XSLT processer
like sablotron, THEN outputting an HTML page."



Can someone show me how using an example?


Thanks,
Richard


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to