#native_company# #native_desc#

Using PHP and XML with Apache Cocoon Page 4

By Darren Beale
on July 30, 2000

We’ve also had to modify our earlier stylesheet

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
<xsl:template match="phpbuilder">
	<xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>
			<title>PHP-XML/XSL/Cocoon Transformation</title>
				<h1><div align="center">
					<xsl:value-of select="heading" />
			<xsl:for-each select="message">
					Hello <xsl:value-of select="greeting" />
The only difference here is the
<xsl:for-each select="message">

this allows us to apply the transformation to any instance of a <greeting> within a <message>
So navigating to phpbuilder.php gives us the following markup to our browser:





<title>PHP-XML/XSL/Cocoon Transformation</title>




<div align="center">This is a Dynamically Generated XML that has been Transformed using XSLT</div>


<p>Hello UK</p>

<p>Hello USA</p>

<p>Hello France</p>

To summarise, we have started with a php script that writes some valid XML to a file and then
redirects to that .xml page. As it’s .XML Cocoon wakes up and starts to parse it, combined
with the XSL we have browser friendly code that was Dynamically generated by PHP.
Create a new Stylesheet for WML and Cocoon will allow you to use the same php code to make a WAP freindly page =)
Good luck