<?
	class GenPage 
	{
		var	$file;
		var     $xml;
		var	$xslt;
		var 	$html;	
		
		function GenPage($file)
		{
			$this->file = $file;
			$this->xml = '';
			$this->xslt = '';
			$this->html = '';
		}
		
		function applyXML($xml)
		{
			$this->xml = $xml;
			//print $xml;
		}

		function applyXSLT($xslt)
		{
			$this->xslt = $xslt;
			// print $xslt;
		}
		
		function process()
		{
			$arguments = array(
			     '/_xml' => $this->xml,
			     '/_xsl' => $this->xslt
			);

			$xh = xslt_create();
			// print getcwd();
			xslt_set_base($xh,'file://'.dirname(__FILE__));
			$res = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); 
			if($res) $this->html = $res;
    			else return $this->file.': [<b><font color="#cc0000"> '.xslt_error($xh).' </font></b>]';
			xslt_free($xh);	
					
			return $this->file;
		}

		function pasteToFile($prefix)
		{
			$fn = $prefix.'/'.$this->file;

			//print $fn."<br>";
			if(file_exists($fn)) unlink($fn);
			if($h = fopen($fn,'w')) {
				fwrite($h,$this->html);
				fclose($h);
			}			
		}

		function pasteToOutput()
		{
			print $this->html;
		}

		function pasteToString()
		{
			return $this->html;
		}
				
	};


?>