Differences between revisions 18 and 20 (spanning 2 versions)
Revision 18 as of 2004-06-25 11:17:49
Size: 5264
Editor: 61:55:33:123
Revision 20 as of 2009-09-20 23:40:04
Size: 4567
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
Line 88: Line 62:
Line 135: Line 110:
''Wonderful. Thank you. I needed this! --- [:Gabridome]'' [[BR]] ''Wonderful. Thank you. I needed this! --- [[Gabridome]]'' <<BR>>
Line 158: Line 133:
[http://cocoon.apache.org/2.1/userdocs/concepts/errorhandling.html Errorhandling documentation] [[http://cocoon.apache.org/2.1/userdocs/concepts/errorhandling.html|Errorhandling documentation]]

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 C!IncludeTransformer

<!-- 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

SitemapPatterns (last edited 2009-09-20 23:40:04 by localhost)