tags. */ $buf = preg_replace("//","/","/","]]>",$buf); $buf = preg_replace("//","/","]]>",$buf); /* Convert tabs to spaces */ $buf = preg_replace("/\t/"," ",$buf); /* is a placeholder, to be replaced by nothing. I use it to fool the regexps above when I want a something to NOT be replaced (like a literal tag in a text section, for example). */ $buf = preg_replace("//","",$buf); /* write processed output file */ $fo = fopen($xml_out,"w"); fwrite($fo, $buf); fclose($fo); } function serve_xml_to_html($xml_file) { global $xslt_file; /* a little sanity checking first */ if(strlen($xml_file) < 5 or (substr($xml_file,strlen($xml_file)-4,4) != ".xml")) { echo "ERROR - Bad filename for xml_file: $xml_file"; return; } if(!file_exists($xml_file)) { echo "ERROR - no such file: $xml_file"; return; } /* get output directory name */ $outdir = dirname($xml_file); /* get base name so I can add .html, etc. */ $name = basename($xml_file,".xml"); /* temporary name for processed XML file */ $xml_p_file = $outdir."/".$name.".xml.p"; /* name for resulting HTML file */ $html_file = $outdir.'/'.$name.".html"; /* does html_file need to be regenerated? yes if: 1. It doesn't exist. 2. XML source file is newer than HTML file. 3. XSLT template is newer than HTML file. */ if (!is_file($html_file) or (filemtime($xml_file) > filemtime($html_file)) or (filemtime($xslt_file) > filemtime($html_file)) ) { /* do CDATA escaping on tags */ add_cdata_to_code($xml_file, $xml_p_file); /* perform XSLT processing */ $xslt = xslt_create(); $res = xslt_process($xslt, $xml_p_file, $xslt_file, $html_file); /* remove temp file */ unlink($xml_p_file); /* check for errors in XSLT processing */ if( !$res ) { $s = "

ERROR processing $xml_file with $xslt_file

"; $s .= "XSLT Error: ".xslt_errno($xslt).": ".xslt_error($xslt); xslt_free($xslt); echo $s; return; } xslt_free($xslt); } /* serve html file */ readfile($html_file); } ?>