Building a CMS, part 2: Taking it to the server - PHP XSLT
(Page 5 of 5 )
XSLT is handled by different extensions, depending upon whether you have PHP 4x or PHP 5x. For this example we will look at how it is done in PHP 4x. Consult the PHP manual at php.net for information on PHP 5.
In our dxml.php file comment out the following line.
header("location:".dirname($_SERVER['PHP_SELF'])."/".$f);
The code below will process the new XML document and send it to the browser as HTML. You can provide a third parameter to xslt_process that is a file name for the result document. Whether you want to take up space with the converted documents on your server or have the server process on the fly for each request is up to you. In the absence of a third parameter we store the result in a variable, which is then echoed to the browser.
$proc = xslt_create(); $result = xslt_process($proc,"release.xsl",$f); xslt_free($proc);
echo($result);
If you decide to let the server do the XSLT processing on each request, this code is what you will need for that request, with $f being the path to the XML document. Otherwise you would simply link to the HTML result document stored on the server.
Conclusion
We have now added server side processing to our press release generator project. The XML file that was generated could easily be transformed using additional stylesheets to other formats in an automated fashion.
To learn more about XSLT go to the W3C website here (http://www.w3c.org/) and here (http://www.w3.org/TR/xslt). There is also an excellent XSLT reference here(http://www.zvon.org/xxl/XSLTreference/Output/) As usual, typing XSLT in Google will lead you to more information as well.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |