cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@cocoon.apache.org
Subject [Cocoon Wiki] Updated: LayoutTemplatePattern
Date Fri, 09 Jul 2004 13:49:06 GMT
   Date: 2004-07-09T06:49:05
   Editor: DerekLastname <dhohls@csir.co.za>
   Wiki: Cocoon Wiki
   Page: LayoutTemplatePattern
   URL: http://wiki.apache.org/cocoon/LayoutTemplatePattern

   Add [:] wrapper for ILinKuo

Change Log:

------------------------------------------------------------------------------
@@ -1,96 +1,96 @@
-Have you ever wondered how to create skins to use in Cocoon? This !LayoutTemplate pattern
for the sitemap allows you to do exactly that. While there are certainly other ways to do
this using xinclude or cinclude, I'm partial to this way of organizing skins myself, as I
believe that it makes the switching out of skins that much easier. ILinKuo
+Have you ever wondered how to create skins to use in Cocoon? This !LayoutTemplate pattern
for the sitemap allows you to do exactly that. While there are certainly other ways to do
this using xinclude or cinclude, I'm partial to this way of organizing skins myself, as I
believe that it makes the switching out of skins that much easier. [:ILinKuo}
 
 The essence of the !LayoutTemplate pattern is that it uses an xslt stylesheet to replace
selected elements in the layout template with corresponding elements in the source xml. It'll
be easier to explain after you've run it within your own Cocoon pipeline to see how it works.
 
 === The setup ===
 My directory structure looks like this:
-{{{
-cocoon
-  - sitemap.xmap
-  - xsl
-      - insertIntoLayoutTemplate.xsl
-  - xml
-      - dummyInsert.xml
-  - templates
-      - dummyTemplate.xml
+{{{
+cocoon
+  - sitemap.xmap
+  - xsl
+      - insertIntoLayoutTemplate.xsl
+  - xml
+      - dummyInsert.xml
+  - templates
+      - dummyTemplate.xml
 }}}
 
 and my sitemap match looks like this:
-{{{
-<map:match pattern="test-layoutTemplatePattern">
-	<map:generate src="xml/dummyInsert.xml"/>
-	<map:transform src="xsl/insertIntoLayoutTemplate.xsl">
-		<map:parameter name="relTemplatePath" 
-			value="../templates/dummyTemplate.xml"/> 
-	</map:transform>
-	<map:serialize type="xml"/>
-</map:match>	
+{{{
+<map:match pattern="test-layoutTemplatePattern">
+	<map:generate src="xml/dummyInsert.xml"/>
+	<map:transform src="xsl/insertIntoLayoutTemplate.xsl">
+		<map:parameter name="relTemplatePath" 
+			value="../templates/dummyTemplate.xml"/> 
+	</map:transform>
+	<map:serialize type="xml"/>
+</map:match>	
 }}}
 
 From the sitemap, you specify a layout template to use (in this case, it's dummyTemplate.xml),
and the stylesheet insert!IntoLayoutTemplate.xsl does the job of looking up corresponding
elements in your template from dummyInsert.xml.
 === The files ===
-{{{
-<!-- dummyInsert.xml -->
-<results>
-	<page-title>Test Page for <b>sitemap template insert pattern</b></page-title>
-	<leftNav><a href="www.apache.org">Apache Rules</a></leftNav>
-	<content>
-		<h1>insert your content here!</h1>
-	</content>
-	<footer>copyright: none</footer>
-</results>
+{{{
+<!-- dummyInsert.xml -->
+<results>
+	<page-title>Test Page for <b>sitemap template insert pattern</b></page-title>
+	<leftNav><a href="www.apache.org">Apache Rules</a></leftNav>
+	<content>
+		<h1>insert your content here!</h1>
+	</content>
+	<footer>copyright: none</footer>
+</results>
 }}}
 In the above file, I have the page elements that I want to insert into the layout template
 
-{{{
-<!-- dummyTemplate.xml -->
-<html xmlns:c-insert="http://apache.org/cocoon/insert">
-<head/>
-<body>
-<c-insert:page-title>page-title goes here</c-insert:page-title>
-<table border="1">
-	<tr><td colspan="2"><c-insert:page-banner/></td></tr>
-	<tr><td rowspan="2" width="200"><c-insert:leftNav/></td>
-		<td width="500"><c-insert:content/></td>
-	</tr>
-	<tr><td><c-insert:footer/></td></tr>
-</table>
-</body>
-</html>
+{{{
+<!-- dummyTemplate.xml -->
+<html xmlns:c-insert="http://apache.org/cocoon/insert">
+<head/>
+<body>
+<c-insert:page-title>page-title goes here</c-insert:page-title>
+<table border="1">
+	<tr><td colspan="2"><c-insert:page-banner/></td></tr>
+	<tr><td rowspan="2" width="200"><c-insert:leftNav/></td>
+		<td width="500"><c-insert:content/></td>
+	</tr>
+	<tr><td><c-insert:footer/></td></tr>
+</table>
+</body>
+</html>
 }}}
 This layout template is a simple four cell table with a top banner, left navigation, central
content area, and footer. I've defined a special namespace "c-insert" to mark those elements
that I want to have replaced. So, <c-insert:page-banner>, <c-insert:leftNav>,
<c-insert:content>, and <c-insert:footer> will get replaced by the corresponding
top-level elements <page-banner> <leftNav> <content> and <footer>
in my source document dummyInsert.xml. However, since the source document doesn't contain
a <page-banner> element, it will simply be removed.
 
 The stylesheet that does all the work is:
-{{{
-<!-- insertIntoLayoutTemplate.xsl-->
-<?xml version="1.0"?>
-<xsl:stylesheet version="1.0"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-	xmlns:c-insert="http://apache.org/cocoon/insert"
-	xmlns:xhtml="http://www.w3.org/1999/xhtml">
-
-<xsl:param name="relTemplatePath"/>
-<xsl:variable name="layoutTemplate" select="document($relTemplatePath)"/>
-
-<!-- Selects the document in the pipeline. The top level elements
-	in this document will be inserted into the layout template -->
-<xsl:variable name="results" select="/"/>
-
-<xsl:template match="/">
-	<xsl:apply-templates select="$layoutTemplate/*"/>
-</xsl:template>
-
-<!-- look up content to be inserted using local-name as key -->
-<xsl:template match="c-insert:*">
-	<xsl:copy-of select="$results/*/*[local-name()=local-name(current())]/node()"/>
-</xsl:template>
-
-<!-- identity transform used to copy all other elements as is -->
-<xsl:template match="@*|node()" priority="-1">
-	<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
-</xsl:template>
-
-</xsl:stylesheet>
+{{{
+<!-- insertIntoLayoutTemplate.xsl-->
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:c-insert="http://apache.org/cocoon/insert"
+	xmlns:xhtml="http://www.w3.org/1999/xhtml">
+
+<xsl:param name="relTemplatePath"/>
+<xsl:variable name="layoutTemplate" select="document($relTemplatePath)"/>
+
+<!-- Selects the document in the pipeline. The top level elements
+	in this document will be inserted into the layout template -->
+<xsl:variable name="results" select="/"/>
+
+<xsl:template match="/">
+	<xsl:apply-templates select="$layoutTemplate/*"/>
+</xsl:template>
+
+<!-- look up content to be inserted using local-name as key -->
+<xsl:template match="c-insert:*">
+	<xsl:copy-of select="$results/*/*[local-name()=local-name(current())]/node()"/>
+</xsl:template>
+
+<!-- identity transform used to copy all other elements as is -->
+<xsl:template match="@*|node()" priority="-1">
+	<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
+</xsl:template>
+
+</xsl:stylesheet>
 }}}
 
 Try it out!

Mime
View raw message