Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Using PHP and XML with Apache Cocoon
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 Transformation Hello 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

'); ?>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
FileGeneratorsaraadmin04/07/05 13:20
Easier way to do thisJim Parslow02/14/05 12:49
error in html?Blithe06/16/03 15:37
RE: Error by Apache:can not load php4apache.dllJim04/07/03 12:22
RE: Error by Apache:can not load php4apache.dllAggie12/04/02 12:42
RE: MYSQL problemsjan_hut11/30/02 13:05
RE: Apache not loading php4apache.dll in W95John10/17/02 18:00
apache2filter.dll fileDirtgod09/29/02 00:42
RE: There must be a better wayNicolas Marchildon09/09/02 19:31
RE: Apache not loading php4apache.dll in W95OpenSource08/30/02 01:31
RE: MYSQL PROBLEMSarreddo Nyang08/16/02 09:01
RE: Error by Apache:can not load php4apache.dEric Dortmans08/14/02 04:34
RE: Error by Apache:can not load php4apache.dRalph08/10/02 15:22
Thanks for your articleJose Manuel Gomez08/06/02 19:00
RE: Error by Apache:can not load php4apache.dllpaul s. k.08/02/02 15:07
RE: Error by Apache:can not load php4apache.dllTim07/22/02 17:17
RE: Error by Apache:can not load php4apache.dllpawelw07/19/02 06:48
RE: Error by Apache:can not load php4apache.dllAndrea07/09/02 09:55
Appending data to XML file by using PHPdongbt06/12/02 00:48
RE: how can i run php-scripts on my apache?dawuss05/15/02 08:55
RE: Output XML from PHPPablo Yamamoto05/13/02 09:57
RE: Error by Apache:can not load php4apache.dllMauricio04/20/02 15:47
PHP NewbieBrett Johanson04/09/02 05:46
RE: Error by Apache:can not load php4apache.dllchristian gibson04/02/02 16:15
RE: There must be a better wayScott C.02/16/02 06:35
Krysalis : Native PHP Cocoon alternativeAlexandru COSTIN01/11/02 07:00
Error by Apache:can not load php4apache.dllharshul11/24/01 06:37
how can i run php-scripts on my apache?jack(absolute beginner)09/27/01 21:51
how to use php page without having Apache?sam09/21/01 06:45
RE: PHP in XSPPablo Liska09/14/01 16:42
The best way to generate xml from phpWojtek Pragacz08/19/01 06:03
Need help in retrieving attribute values Taj07/30/01 22:54
RE: Writing to a file is ugly! Why not xinclude?BKoo07/08/01 12:01
The World is Crazy, Crazy Crazy!!!Carlos G. Varela06/28/01 02:10
PHP Sablotron Extension V Cocoon ?tim05/17/01 14:26
RE: Writing to a file is ugly! Why not xinclude?Matt05/04/01 12:19
RE: Writing to a file is ugly! Why not xinclude?Charlie Waters04/30/01 17:10
Output XML from PHPMickey04/25/01 13:28
Multiple requests to the PHP codeDavid Durham04/08/01 15:07
another php/cocoon kludgeAki Sasaki03/15/01 21:55
How to save client side Xml file on the serveD.P.Batagoda02/18/01 22:29
RE: Writing to a file is ugly! Why not xinclude?Ralph Wiggam01/30/01 11:59
XML Can't Parse an ENTITYMarc Steel01/16/01 22:47
Writing to a file is ugly! Why not xinclude?Sergio Carvalho01/02/01 18:52
PHP in XSPRapheal Kaplan11/06/00 23:13
efficiency?Terence10/27/00 11:54
XML MessagingEverton de Brito Dias09/11/00 12:54
Messaging applicationEverton de Brito Dias09/10/00 17:35
XML paradigmEverton de Brito Dias09/10/00 17:32
Maybe a better way...David Dossot08/29/00 11:18
RE: There must be a better wayljpit07/14/00 17:56
RE: There must be a better wayBealers07/10/00 18:48
There must be a better waymatt mcConnell07/08/00 01:51
PDF formattingRob Wills07/04/00 00:00
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.