cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Schatten <ala...@gmx.at>
Subject Re: html templates - best practise
Date Fri, 03 Oct 2003 16:29:50 GMT
I developed a way of "callback" templates. Look at this:

(0) consider a HTML design like this:

+--------------------------------------------+
| Page Title (each page different)           |
+--------------------------------------------+
| Main Navigation (for all pages the same    |
+--------------------------------------------+
|                                            |
|                                            |
| Content (each page different)              |
|                                            |
|                                            |
|                                            |
+--------------------------------------------+
| Footer (each page different)               |
+--------------------------------------------+


(1) first of all there is the default.xsl stylesheet it looks (very 
reduced version) like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
encoding="iso-8859-1" version="1.0">

    <xsl:variable name="menu" select="document('../xml/menu.xml')"/>

    <xsl:template match="/">
        <html>
            <head>
                <title>Cocoon Day 2003</title>
                <link href="style.css" rel="stylesheet" type="text/css" />
            </head>

            <body>
            <!-- snip: here is the html part for the navigation header -->
            <xsl:call-template name="title"/>
            <!-- end of html navigation part -->

            <!-- / snip here is the html part surrounding the content -->
            <xsl:apply-templates /> oder <xsl:call-template 
name="content"/>
            <!-- end of html content part -->

            <!-- / snip here is the html part surrounding the footer -->
            <xsl:call-template name="footer"/>
            <!-- end of html content part -->

            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>


(2) then there are the specific stylesheets for different parts of the 
website, looking like this:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    encoding="iso-8859-1"
    version="1.0">

    <xsl:include href="default.xsl"/>

    <xsl:template name="title">
        Titel
    </xsl:template>

    <xsl:template name="content">
        <!-- add XSL and other code to generate content part -->
    </xsl:template>

    <xsl:template name="footer">
        <!-- add XSL and other code to generate footer part -->
    </xsl:template>
   
</xsl:stylesheet>


the include includes the default stylesheet, in which the root template 
it the first to be executed. then, this root template builds the  HTML 
"frame" and calls the named templates to fill in the concrete content.

The main advantage is this: in the default.xsl stylesheet inside the 
root template is xhtml that can be edited with any editor e.g. 
dreamweaver. the only xsl tags are the 2 or 3 call-templates and those 
are usually ignored by html editors like dreamweaver.

I use this in many projects and it works excellent also offline (with 
normal XSLT transformation e.g. using ANT).

alex


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message