Filter Transformer
http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Main
User Documentation

Transformers
Overview

Default
XSLT Transformer

Core
Fragment Extractor Transformer
I18n Transformer
Log Transformer
SQL Transformer
Filter Transformer
Read DOM Session Transformer
Write DOM Session Transformer
XInclude Transformer
CInclude Transformer
EncodeURL Transformer
SourceWriting Transformer

Optional
XT Transformer
LDAP Transformer

Filter Transformer

The filter transformer can be used to let only an amount of elements through in a given block.

  • Name : filter
  • Class: org.apache.cocoon.transformation.FilterTransformer
  • Cacheable: no.

When you for example query a database and it returns too many rows too process at once, you might want to take a block of elements, process this block and ignore the rest for now. You can best compare it to a search on Google: they only return 10 results in one time, for more results you have to click on another block (page). It wouldn't be wise to process more than 10 elements in the pipeline if you only need to display 10 elements.

Assume that a query returns 56 row elements (by using the SQLTransformer) and that you only want to display the first 10 elements:

Output XML from the SQLTransformer:

     
      <rowset nrofrows="56" name="test" 
xmlns="http://apache.org/cocoon/SQL/2.0">
        <row>
          <!-- db record -->
        </row>
        <row>
          <!-- db record -->
        </row>
        <row>
          <!-- db record -->
        </row>

        ...

        <row>
          <!-- db record -->
        </row>
      </rowset>
     
    

By adding following lines to the sitemap, just under the SQLTransformer, you restrict the results to 10 elements in the first block:

     
      <map:transform type="filter">
        <map:parameter name="element-name" value="row"/>
        <map:parameter name="count" value="10"/>
        <map:parameter name="blocknr" value="1"/>
      </map:transform>
     
    

output XML:

     
      <rowset nrofrows="56" name="test" 
xmlns="http://apache.org/cocoon/SQL/2.0">
        <block id="1">
          <row>
            <!-- db record -->
          </row>

          <!-- total of 10 rows -->

          <row>
            <!-- db record -->
          </row>
        </block>
        <block id="2"/>
        <block id="3"/>
        <block id="4"/>
        <block id="5"/>
        <block id="6"/>
      </rowset>
     
    

To make it more dynamically, put something like {reqCount} and {reqBlock} in the values for count and blocknr respectively. These can be parameters from the request and they can be passed to the sitemap with an action.

The FilterTransformer is a standalone component, you don't need to use it in combination with the SQLTransformer.

Copyright © 1999-2002 The Apache Software Foundation. All Rights Reserved.