cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Horsfield, Peter A." <peter.horsfi...@ngc.com>
Subject RE: html templates - best practise
Date Fri, 03 Oct 2003 16:57:44 GMT
One thing I think nobody has mentioned yet is the use 
of the cocoon:/ internal pipeline call.

Using that in conjunction with the XSLT document function means
you get to take advantage of Cocoon pipelines for fragments of 
presentation or data XML, whatever format. You can also then
feed in the particular fragments using XSLT parameters 
specified in the sitemap, and hence based on the request.

The problem with using this indirection is that you may bypass a 
little bit of the Cocoon framework. In particular, I think one 
of the articles that someone linked too mentioned
that Cocoon or XSLT blindly caches the document accessed by the 
document() function. This is obviously no good if the URI indicates
a resource that might change ( anyone know for sure? )

The other XSLT issue is the way it can implicitly fall back to a 
non-streamed approach. I suspect that carefully written XSLT will
maintain the SAX streaming without caching it all first. However
as soon as you use the document function to merge two inputs, 
you're caching the secondary input. In general I've seen that 
presentation XML is larger/longer than data XML which is why I 
access data through the document() function and not presentation.

The alternative to XSLT I've seen around is STX, streaming 
transformations for xml, but I've not used it. Streaming/Merging
two SAX event streams does seem like a thorny problem at first
glance though.

Also, bear in mind that as soon as you embed XHTML within your
XSLT directly, you limit yourself to Altova products as the only
IDE capable of understanding what you've done. The majority of
IDEs out there still spend the majority of their time trying
to understand the various finicky bits of HTML4 and less on 
understanding XML namespaces.

Regards,

Peter

-----Original Message-----
From: Alexander Schatten [mailto:alasan@gmx.at]
Sent: Friday, October 03, 2003 12:30 PM
To: users@cocoon.apache.org
Subject: Re: html templates - best practise


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

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


Mime
View raw message