September 27, 2002

Why map:aggregate is harmful


Steven Noels explains the difference between <map:aggregate> and the cinclude transformer in Cocoon when composing aggregated XML documents, like HTML pages for portals. Subtle differences which I didn't realize so far: great stuff, thanks Steven!

The basic difference is in the way the generation of the final aggregated page happens. The <map:aggregate> is a sitemap construct, which essentially places the included XML content from the different source inside some XML elements. Here is an excerpt from Cocoon's samples sitemap entry:

  <map:match pattern="news/aggregate.xml">
   <map:aggregate element="page" ns="">
     <map:part element="news" ns="" src="cocoon:/news/slashdot.xml"/>
     <map:part element="news" ns="" src="cocoon:/news/moreover.xml"/>
     <map:part element="news" ns="" src="cocoon:/news/xmlhack.xml"/>
    <map:transform src="stylesheets/news/news.xsl"/>

With <map:aggregate> you need to apply an additional transformation step to translate the resulting XML document to (X)HTML.

In contrast cinclude is a transformer which processes a template file with placeholders for the content to be inserted instead. Here's a simple file which could be fed to the cinclude transformer (assume the file is named aggregate.xml):

   <title>A Simple Page using Content Aggregation</title>
      <cinclude:include src="cocoon:/news/slashdot.xml" element="slashdot" ns=""/>
      <cinclude:include src="cocoon:/news/moreover.xml" element="moreover" ns=""/>
      <cinclude:include src="cocoon:/news/xmlhack.xml" element="isyndicate" ns=""/>

The equivalent sitemap entry would look like (adapted from Cocoon's samples sitemap):

  <map:match pattern="news/aggregate">
   <map:generate src="file/aggregate.xml"/>
   <map:transform type="cinclude"/>
   <map:transform src="stylesheets/news/news.xsl"/>

In the case of the cinclude transformer, we can avoid the last transformation by modifying our aggregate.xml to contain only the necessary (X)HTML html, body, table and/or div elements to give structure to the aggregated XML/XHTML documents.

Posted by ovidiu at September 27, 2002 01:52 AM |
Copyright © 2002-2016 Ovidiu Predescu.