cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter van Hardenberg <>
Subject Re: Advice on site design - really close
Date Wed, 20 Jul 2005 15:19:53 GMT
Hi Jan,

we recently had this same problem at the Internet Shakespeare Editions. Here's what I came
up with.

First, I was disappointed to discover resources can't be inherited, so I created a match-rule
like this in the root sitemap.

   <map:match pattern="add-template"> 
  <map:call resource="add-template"/>

The resource that lives in my root sitemap looks like this:

  <map:resource name="add-template">
   <map:generate src="style/include-template.xslt">
   <map:transform type="xinclude"/>
   <map:serialize type="xml"/>

We're almost done now, all we need is to write the include-template XSLT. Include-template
takes an XHTML file and builds it into a templated XHTML file. It does this by creating itself
out of a source XSLT file and a few XIncluded XHTML snippets.
style/include-template.xslt is essentially a souped up identity transform. I have trimmed
it down somewhat to make the email more legible, and to remove some obscuring logic for template
selection and peer-review status watermarking.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" version="1.0"
<xsl:output method="xhtml" indent="no"/>

<xsl:template match="/xhtml:html">
<html xmlns=""

 <!-- construct the header of the file by prepending the default header stuff to the source
  <!--- add these tags to the new document head -->
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="template/css/base.css" rel="stylesheet" type="text/css" />

  <!-- copy in the source doc's head -->
  <xsl:apply-templates select="xhtml:head"/>
  <!-- add the template header -->
  <xi:include href="../template/normal-header.xml"/>
  <xi:include href="../template/normal-academic.xml"/>

  <div id="content">
    <!-- copy through the body of the source page into the content section -->
    <xsl:apply-templates select="xhtml:body"/>
  <!-- add the footer. -->
  <xi:include href="../template/normal-footer.xml"/>

<!-- these make sure that when you hit a body tag, the contents make it through "unwrapped"
<xsl:template match="xhtml:body">

<xsl:template match="xhtml:head">

<!-- this is known as the identity transform. it passes everything else through untouched.
<xsl:template match="node( ) | @*">
  <xsl:apply-templates select="@* | node( )"/>


That's essentially the whole shebang. The only thing left is how to apply the template. This
part is easy!

   <map:match pattern="someMatchRule">
    <map:generate src="content/yourContent.xml"/>
    <map:transform src="style/theUsual.xslt">
    <map:transform src="cocoon://yourSiteRoot/add-template"/> 
    <map:serialize type="xhtml"/>

Hope that helps!

> >>>Basically, the site has a header, footer and two
> >>>sidebars with content in the middle.  In JSP, I
> >>
> >>would
> >>
> >>>just have includes on every page for the header,
> >>>footer, etc.  However, in Cocoon, I was hoping I
> >>
> >>could
> >>
> >>>have one "template" page that decided the layout.
> >>>

View raw message