Hey PHP-gurus!

How do I run and invoke PHP XSL-parsing and
transformation using PHP version 4.0.6.?

Here is the sample code I want to run.

files included:
  XML-file and XSL-file:They are formatted nicely
client-side by IE6.0.
  (Please disregard the stupid text in the XML-file,
it is an extract from a database with a lot of test

When I run the script (post.php) I get an 'empty'
XHTML-document, which is probably the result of
applying the 
XSL-stylesheet(standard.xsl) on the XML-document
(writeout.xml), and getting nothing -> a 'bad'

The script doen't display any errors, and the logging
does not seem to work.
Please help.

PS : I didn't do the server setup myself, how can I
check if the XSL-parser is configured correctly?

Karsten Pihl, denmark

Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax

// constants
define(XSL1, "standard.xsl");
define(XMLLINK, '<?xml-stylesheet type="text/xsl" href="'.XSL1.'"?>');  
define(XMLHEAD, '<?xml version="1.0" encoding="iso-8859-1"?>'."\n".XMLLINK);
define(XMLFILE, "writeout.xml");
define(LOG, 'transform.log');

// ## executing

// functions
function load($fromFile){
  //returns file $fromFile as string $str
  $fh = fopen($fromFile, "r") or die("Can't open file ".$fromFile);
  $str = fread($fh, filesize($fromFile));
  return $str;

function save($str, $toFile){
// writes string $str to file $toFile, returns boolean for succes
  $fh = fopen($toFile, "wb") or die("Can't open file ".$toFile);
  $bf = fwrite($fh, $str);
  if ($bf == -1) return false;
  else return true;

function transform(){
  // echo 'valid: ', $valid_user; 
  // almindelige brugere må gerne se nyheder
  // filtrerer(parser) xml dokumentet igennem stylesheet'et.
  $myxml = load(XMLFILE);
  $mystyle = load(XSL1);
  $handle = @xslt_create() or die("Can't create XSLT handle!");
  xslt_set_log($handle, true);
  xslt_set_log($handle, getcwd().LOG);

   // $xsltproc = xslt_create();
  // create processer handle 
  echo $handle;

  // do transformation
  $result = xslt_process($handle, $myxml, $myxsl);
  // echo $out; 
  // echo 'res', $result;
  if ($result){
    echo $result; 
    // pre($result);
    $res = $result;
   $res = "error occurred during transformation : ".xslt_error($handle); 
   $res.= " with error code: ".xslt_errorno($handle); 
  // Free ressources
  return $res;
} // transform;

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="standard.xsl"?>
<news id="2"><date>7/4/2002</date>
<body>Sunday evening is quit</body>
<news id="3"><date>30/3/2002</date>
<body>The weather is beutifull today</body>
<news id="4"><date>4/4/2002</date>
<news id="5"><date>4/4/2002</date>
<body>Advanced Object-oriented programming.
A very interesting subject</body>
<news id="6"><date>4/4/2002</date>
<body>At tuesdays: webprogramming</body>
<news id="7"><date>30/3/2002</date>
<body>I am happy today.</body>
<news id="8"><date>4/4/2002</date>
<body>Sunday evening is quit yes yes yes yes</body>

<?xml version="1.0"?>
<xsl:stylesheet version="1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns="http://www.w3.org/1999/xhtml";>
  <xsl:output method="html" encoding="iso-8859-1"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"

<xsl:template match="allnews">
  <head><title>My news</title></head>
    <xsl:apply-templates select="news"/>

<xsl:template match="news">
    <xsl:value-of select="section" />
    <xsl:value-of select="date" />
     <xsl:value-of select="time" />
  <h1><xsl:value-of select="header" /></h1>
  <h2><xsl:value-of select="body" /></h2>

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

Reply via email to