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"/>
   </map:match>

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

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

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="http://www.w3.org/1999/XSL/Transform"; version="1.0"
                xmlns:xi="http://www.w3.org/2001/XInclude/";
          xmlns="http://www.w3.org/1999/xhtml";
                xmlns:xhtml="http://www.w3.org/1999/xhtml";>
<xsl:output method="xhtml" indent="no"/>

<xsl:template match="/xhtml:html">
<html xmlns="http://www.w3.org/1999/xhtml";
      xmlns:xi="http://www.w3.org/2001/XInclude";>

 <!-- construct the header of the file by prepending the default header stuff 
to the source -->
 <head>
  <!--- 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"/>
 </head>
 <body>
  
  <!-- 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"/>
  </div>
  
  <!-- add the footer. -->
  <xi:include href="../template/normal-footer.xml"/>
 </body>
</html>
</xsl:template> 

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

<xsl:template match="xhtml:head">
 <xsl:apply-templates/>
</xsl:template>

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

</xsl:stylesheet>

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"/>
   </map:match>

Hope that helps!

-pvh
 
> >>>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.
> >>>

Attachment: pgpdJutJ9wZQ6.pgp
Description: PGP signature

Reply via email to