[geeks] using script to generate files from a template

William S. wstan at xs4all.nl
Sun Jun 16 05:59:44 CDT 2002


On Sun, Jun 16, 2002 at 05:24:44AM -0500, Bill Bradford wrote:
> 
> Look at using PHP functions.  Here's kinda how I do a lot of the SunHELP
> stuff.  
> 
> Here's the main index.php for the site:
> 
> 
> <?
>         include ( 'backend/makepage.inc');
>         makepage(
> 		'news',
> 		'news',
> 		'xml/news.php'
> 		);
> ?>
> 
This is my index.php for my "prototype" site:

	<?php 
	$xml = "./index.xml";
	$xsl = "./index.xsl";

	$_parser = xslt_create(); 

	if( !$result = @xslt_process(  $_parser,    // resource xh
       	                        $xml,        // string xml
       	                        $xsl,        // string xsl
       	                        NULL,        // string result
       	                        array(),     // array arguments
       	                        array()      // array parameters
       	                      ) ) {
	    printf( "Sablotron Error (%s): <br /><strong>%s</strong>", 
	            xslt_errno($_parser), xslt_error($_parser) );
	}
	xslt_free($_parser);
	echo $result;
	?>

<snip>
> 
> Here's the "makepage.inc" file, slightly edited (you can see where I insert
> the variables that were passed to the function).  To add a new page to the
> site, I simply make a new <pagename>.php file, edit those three parameters,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
It is this particular item that I am trying to generate with the script.
I would like to create 50+ *.php files that will be linked to on the
menu table on a web page. Each *.php file will reference a
different *.xsl (stylesheet) and *.xml (content/database file).
For instance, boston.php will specify boston.xsl amd boston.xml to
transform. boston.xsl will format a sorted table based on information
in that city; boston.xml will be a database with that information that will
be dynamic in content and accept records submitted from a web form.

I am not sure if this is the right way to do this but it looks like it will
work once the initial setup part is done. Is there a good working example
of this anywhere else? Part of my reason for using the Sablotron transformation
is to enable this process to produce content in WAP format, text, and PDF.

> then create the .html file that goes in it.  Allows me to change the entire
> site look by editing the makepage.inc file.
> 

<snip>
-- 
Bill
Amsterdam, NL



More information about the geeks mailing list