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:
  PHP-script
  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
postings)

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'
transformation.

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?

YT
Karsten Pihl, denmark




__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
<?php

// 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
transform();

// 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));
  fclose($fh);
  return $str;
}//load

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);
  fclose($fh);
  // 
  if ($bf == -1) return false;
  else return true;
}//save


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;
  }
  else{ 
   $res = "error occurred during transformation : ".xslt_error($handle); 
   $res.= " with error code: ".xslt_errorno($handle); 
  }
  // Free ressources
  @xslt_free($handle);
  return $res;
} // transform;


?>
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="standard.xsl"?>
<allnews>
<news id="2"><date>7/4/2002</date>
<time>22:48</time>
<header>Sunday</header>
<section>comment</section>
<body>Sunday evening is quit</body>
</news>
<news id="3"><date>30/3/2002</date>
<time>13:47</time>
<header>Sunday</header>
<section>weather</section>
<body>The weather is beutifull today</body>
</news>
<news id="4"><date>4/4/2002</date>
<time>18:45</time>
<header>Thursday</header>
<section>comment</section>
<body>Databasesystems</body>
</news>
<news id="5"><date>4/4/2002</date>
<time>18:46</time>
<header>Monday</header>
<section>comment</section>
<body>Advanced Object-oriented programming.
A very interesting subject</body>
</news>
<news id="6"><date>4/4/2002</date>
<time>18:46</time>
<header>Thuesday</header>
<section>calender</section>
<body>At tuesdays: webprogramming</body>
</news>
<news id="7"><date>30/3/2002</date>
<time>13:52</time>
<header>Saturday</header>
<section>comment</section>
<body>I am happy today.</body>
</news>
<news id="8"><date>4/4/2002</date>
<time>20:25</time>
<header>Sunday</header>
<section>comment</section>
<body>Sunday evening is quit yes yes yes yes</body>
</news>

</allnews>
<?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"
        doctype-system="DTD/xhtml1-transitional.dtd"
        indent="yes"/>

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

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








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

Reply via email to