While working with Cocoon, I have come upon some useful patterns for use in the sitemap. Feel free to change/tweak these as needed. – TonyCollen


  • Most basic usage of sitemap components
  • Usually generating from static XML files
  • Good candidate for pre-generation using CLI
<map:match pattern="*.html">
    <map:generate src="documents/{1}.xml"/>
    <map:transform src="stylesheets/docbook2html.xsl"/>
    <map:serialize type="xhtml"/>

Recursive Match/Generate/Transform/Serialize

  • Useful for automated M/G/T/S
  • Allows people to create subdirectories and Cocoon will automatically serve them
  • Will match foo/blah.html, foo/bar/blah.html, foo/bar/baz/blah.html, etc.
  • Centralized XSLT for unified document structure
<map:match pattern="**/*.html">
    <map:generate src="documents/{1}/{2}.xml"/>
    <map:transform src="stylesheets/docbook2site.xsl"/>
    <map:serialize type="html"/>

Redirect "empty" requests to a known URI

  • Similar to DirectoryIndex directive in httpd.conf
<map:match pattern="">
    <map:redirect-to uri="welcome"/>

Sub-Sitemap Automounting

  • Used in default [Sitemap]

  • Minimizes maintenance of parent sitemaps
  • Extremely useful
<map:match pattern="*/**">
    <map:mount check-reload="yes" src="{1}/" uri-prefix="{1}"/>

Dynamic Mounting – AndreasHartmann

  • dynamic selection of the sitemap to process a URL
  • allows specific handling of a certain URL by subsites or site sections
<map:match pattern="*/**-info.html">
  <map:act type="resource-exists" src="{1}/info.xmap">
    <map:mount src="{1}/info.xmap" uri-prefix="{1}"/>

[...] (further processing of this URL)

Fallback Transformation – AndreasHartmann

  • typical examply of resource-exists selector usage
  • allows dynamic selection of a general or specific stylesheet
  • easily reusable when implemented as a resource
  • allows "inheritance" of stylesheet sets - typically the specific stylesheet imports the general one
  • also useful for XML source documents
<map:match pattern="**/*.html"
  <map:generate src="content/{1}/{2}.xml"/>
  <map:select type="resource-exists">
    <map:when test="xslt/{1}/document2page.xsl">
      <map:transform src="xslt/{1}/document2page.xsl"/>
      <map:transform src="xslt/document2page.xml"/>

DirectoryGenerator and CIncludeTransformer

<!-- overview page -->
<!-- pattern="{area}/{doctype}/{document-id}.html" -->
<map:match pattern="*/overview.html">
  <map:generate type="directory" src="content/{1}">
    <map:parameter name="sort" value="date"/>
  <map:transform src="xslt/directory2include.xsl"/>
  <map:transform type="cinclude"/>
  <map:transform src="xslt/overview/include2html.xsl"/>

Other Pattern Pages:

Readers' comments

Wonderful. Thank you. I needed this! — Gabridome

Thanks a lot, though I'm missing pattern for usefull errorhandling! — Gernot

  • Really simple, when processing something you can most often catch unknown errors with a generic exceptionhandler, those errors can at least give different messages based on a match in the errorhandler.
<map:selector name="exception" src="org.apache.cocoon.selection.XPathExceptionSelector">
	<exception class="java.lang.Throwable" unroll="true"/>
  • When your content is generated by xsl, the dummy xml file can be used for error messages.
<map:match pattern="**.xml">
	<map:generate src="common/error.xml"/>
	<map:select type="resource-exists">
		<map:when test="{1}.jpg">
		<map:transform src="style/picture.xsl">
			<map:parameter name="name" value="{1}"/>

Errorhandling documentation --- Patrik C

  • No labels