Aggregation
Aggregation is one of the most useful facilities of Cocoon and Paloose. It takes several XML documents
and aggregates them into a single XML document with appropriate enclosing tags for each part. Within the
<map:aggregate> element there are a number of <map:part> elements that define which XML documents should be aggregated together. A working example is
given here.
The <map:aggregate> element has a single attribute
- element — the parent element within which the entire aggregated document must be
placed.
Each <map:part> element has a number of attributes that control how each part is to be
included:
- src — the name and location of the document to be included. Pseudo protocols can be
used (although full URLs have not been implemented in Paloose yet).
- element — the parent element within which this part must be placed.
- strip-root — if this is "true" then the root element of the included document will be
removed before inclusion.
As an example of aggregation consider the following extract from the Paloose site (note the use of an internal only
pipeline):
<map:pipelines>
<map:pipeline>
<map:match pattern="**.html">
<map:aggregate element="root" >
<map:part src="cocoon:/headings.xml" element="headings" strip-root="true"/>
<map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/>
<map:part src="cocoon:/newsArticles.xml" element="news-articles" strip-root="true"/>
<map:part src="cocoon:/{1}.xml" element="content" strip-root="true"/>
</map:aggregate>
...
</map:match>
</map:pipeline>
<map:pipeline internal-only="true">
<map:match pattern="menus.xml">
<map:generate src="context://content/menus.xml"/>
<map:serialize/>
</map:match>
<map:match pattern="headings.xml">
<map:generate src="context://content/headings.xml"/>
<map:serialize/>
</map:match>
<map:match pattern="newsArticles.xml">
<map:generate src="context://content/newsArticles.xml"/>
<map:serialize/>
</map:match>
<map:match pattern="**.xml">
<map:generate src="context://content/{1}.xml"/>
<map:serialize/>
</map:match>
</map:pipeline>
</map:pipelines>
This will produce an aggregated document:
<?xml version="1.0"?>
<root>
<headings>
...
</headings>
<menus>
...
</menus>
<news-articles>
...
</news-articles>
<content>
...
</content>
</root>
Copyright 2006 – 2023 Hugh Field-Richards. All Rights Reserved.