#native_company# #native_desc#
#native_cta#

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" 
				version="1.0">
<xsl:template match="phpbuilder">
	<xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>
	<html>
		<head>
			<title>PHP-XML/XSL/Cocoon Transformation</title>
		</head>
		<body>
			<p>
				<h1><div align="center">
					<xsl:value-of select="heading" />
				</div></h1>
			</p>
			<xsl:for-each select="message">
				<p>
					Hello <xsl:value-of select="greeting" />
				</p>
			</xsl:for-each>
		</body>
	</html>
</xsl:template>
</xsl:stylesheet>
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:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"

              "http://www.w3.org/TR/REC-html40/strict.dtd">

<html>

<head>

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

</head>

<body>

<p><h1>

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

</h1></p>

<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
–Bealers

1
|
2
|
3
|
4