Apache » Cocoon »

  Cocoon Core

Cocoon Core 2.2



Generates an XML collection listing performing XPath queries on XML sources.

Basic information

Component typeGenerator
Cocoon blockcore
Java classorg.apache.cocoon.generation.XPathTraversableGenerator
Name in Sitemap
CacheableYes - Yes


It will perform an XPath query on every XML resource, where "xml resource" is, by default, any resource ending with ".xml", which can be overriden by setting the (regexp) pattern xmlFiles (this has the effect of increasing, not limiting, the scope of the search) as a sitemap parameter, or where the name of the resource has a container-wide mime-type mapping to 'text/xml' such as specified by mime-mapping elements in a web.xml descriptor file. The XPath can be specified in two ways:

  1. By using an XPointerish syntax in the URL: everything following the pound sign (possiby preceding query string arguments) will be treated as the XPath;
  2. Specifying it as a sitemap parameter named "xpath"
Note: Since XPathTraversableGemerator is a subclass of TraversableGenerator,  it uses the same set of parameters ( adding some of its own though). Please reer to the TraversableGenerator documentation for an explanation on the use of depth, exclude, include, etc. parameters.

Sample usage:

<map:match pattern="documents/**">
	<map:generate type="xpathtraversable" src="docs/{1}#/article/title|/article/abstract" >
     		<map:parameter name="xmlFiles" value="\.xml$"/>
	<map:serialize type="xml"/> 


   name="test" lastModified="1010400942000"
   date="1/7/02 11:55 AM" requested="true"
   <collection:collection name="subdirectory" lastModified="1010400942000" date="1/7/02 11:55 AM" />
   <collection:resource name="test.xml" lastModified="1011011579000" date="1/14/02 1:32 PM">
     <collection:xpath docid="test.xml" query="/article/title">
       <title>This is a test document</title>
         <para>Abstract of my test article</para>
   <collection:resource name="test.gif" lastModified="1011011579000" date="1/14/02 1:32 PM">
Note: If you need to use namespaces, you can set them as sitemap parameters in the form:
<map:parameter name="xmlns:your prefix" value="nsURI"/**">

Another sample usage:

      <map:match pattern="pages.xml">
        <map:generate type="xpathtraversable" src="blockcontext:/">
          <map:parameter name="depth" value="4"/>
          <map:parameter name="exclude" value="xslt$|xmap$"/>
          <map:parameter name="xmlFiles" value="\.jx$"/> 
          <map:parameter name="xpath" value="/*/content/title"/>
        <map:serialize type="xml"/>
This sitemap fragment will execute the "/*/content/title" XPath expression for all XML files (including the ones ending with ".jx" but excluding the ones ending with "xslt" or "xmap") for a depth of 4 nesting across every block defined in the current block.