#native_company# #native_desc#
#native_cta#

Using PHP and XML with Apache Cocoon Page 2

By Darren Beale
on July 30, 2000

Stage 1) Static XML

How to write XML is outside of the scope of this article, but here is a simple XML page called phpbuilder.xml so you can see how it is laid out.
Initially we have our “Prolog” including a declaration that tells Cocoon that we want to do an XSLT transformation:

<?xml version="1.0"?>
<?xml-stylesheet href="phpbuilder.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>
Now we write out our body elements that contain a message that you’ve seen once or twice before:
XML/XSL/Cocoon TransformationHello World ‘);
?>
My browser (almost certainly) wants HTML, so I use an XSL page to make sense out of the XML:

<?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"
	<html>
		<head>
			<title>XML/XSL/Cocoon Transformation</title>
		</head>
		<body>
			<p>
				<h1><div align="center">
					<xsl:value-of select="heading" />
				</div></h1>
			</p>
			<p>
				<xsl:value-of select="message" />
			</p>
		</body>
	</html>
</xsl:template>
</xsl:stylesheet>
Notice that the HTML is embedded in the Stylesheet with references to my “heading”

‘); ?>

and my message

‘); ?>

Also notice that all of my HTML tags have their end equivalents, e.g. </p>.
You cannot get away without closing a particular tag with XML as it does not conform, if you had a
tag such as <br>, it would be written <br/> which indicates that it is an empty tag.
By saving the above example out as phpbuilder.xsl and navigating to my phpbuilder.xml file on a server with Cocoon installed, I would get the resulting HTML:

Cocoon Static Transformation

This is an XML/XSL Transformation ?? Stage 1

Hello World

‘); ?>