IMHO the most basic thing you will want to do is perform an XSL transformation on an XML file. A typical example of this is to render some XML as an HTML page using an XSL stylesheet.
Take the following XML file (basic01-01.xml):
 |  |  |
 |
<?xml version="1.0"?>
<page>
<title>Basic XML/XSL Transformation Example - BASIC01-01.XML</title>
<greeting>Hello World</greeting>
</page>
|  |
 |  |  |
And use the following XSL to transform it to some HTML (basic01-01.xsl):
 |  |  |
 |
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="page">
<html>
<head>
<title><xsl:value-of select="title"/></title>
</head>
<body>
<h1><xsl:value-of select="title"/></h1>
<p><xsl:value-of select="greeting"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|  |
 |  |  |
Hopefully the basic XSL makes sense however the key to getting this served is to change setting in the sitemap.xmap file. It is this file that determines what and how gets served. The sitemap is very powerful and can be configured to do some very efficient things, however we will start with slightly longwinded but simple examples so the concepts are there to be built on.
You can add sections into sitemap.xmap file that comes with C2. This has things called "pipelines" already set up. To be able to see the result of transforming the above files together you just need to add the following code into the last "pipeline" section:
 |  |  |
 |
<map:match pattern="ctwig/basic01-01.xml">
<map:generate type="file" src="ctwig/basic01-01.xml"/>
<map:transform type="xslt" src="ctwig/basic01-01.xsl"/>
<map:serialize/>
</map:match>
|  |
 |  |  |
What this construct does is to tell C2 to do something when it recieves a request for ctwig/basic01-01.xml
. The "something" that C2 will do is pass the ctwig/basic01-01.xml
file through a "file" generator. This basically parses the XML. The result parsed stream then gets transformed using ctwig/basic01-01.xsl
and rendered.
Calling http://localhost:8080/cocoon/ctwig/basic01-01.xml will result in a simple HTML page being rendered.