Generating Web content with Cocoon (2/2) - exploring XML | WebReference

Generating Web content with Cocoon (2/2) - exploring XML

Generating Web content with Cocoon

Transformers are the main processing component that manipulate data before it is output to a Web client. They are both the source and sink of SAX events and can be plugged together to an arbitrary depth. The most popular component in this category is the XSLT transformer. It encapsulates an XSLT processor that applies an XSLT style sheet to the incoming SAX events and emits new events for the transformed result.

Several serializers are available for converting the available XML data into various other formats. They are the endpoint of any processing pipeline. Serializers exist for HTML, PDF and even image formats:

Last, but not least, matchers and selectors introduce some conditional processing in a pipeline. A matcher works similar to an Apache Alias directive, it ties any URL that matches the given regular expression to a processing pipeline. Selectors are if-then-else constructs.

Pipeline configuration

A transformation needs at least one generator, one transformer and one serializer. Let's take a DocBook XML document, transform it with XSLT and output it as HTML:

  <map:match pattern="index.html">
    <map:generate src="index.xml"/>
    <map:transform src="docbook2html.xsl"/>
    <map:serialize type="html"/>

Easy, isn't it?


The Cocoon framework is a powerful software application for dynamically generating Web content without needing to know a programming language. Although it is written in Java, by no means do you have to use or know Java, short of configuring a Web application for a servlet engine such as Tomcat. Cocoon 2 eliminates the shortcomings of Version 1 and provides an interesting alternative to your favorite scripting language.

Produced by Michael Claßen

Created: Mar 18, 2002
Revised: Mar 18, 2002