Setting up Cocoon to use XSLT 2.0

March 8, 2008

Notes on setting up Cocoon to use XSLT 2.0 under Tomcat are already on the web, but in the spirit of repitition:

  • For support of XSLT 2.0, you need to add and configure the Saxon 9 libraries. Get the Saxon-B download from here. Then extract all the .jar libraries into cocoon/WEB-INF/lib.
  • Now we need to configure Cocoon so that Saxon can be called. First, open cocoon/WEB-INF/cocoon.xconf, and find the bit that refers to Saxon XSLT, which is commented out by default. Uncomment the code and change it according to the instructions in the file, so that it enables Saxon 9:
          	<component logger="core.xslt"
                       role="org.apache.excalibur.xml.xslt.XSLTProcessor/saxon"
                       class="org.apache.cocoon.components.xslt.TraxProcessor">
                <parameter name="use-store" value="true"/>
                <parameter name="transformer-factory" value="net.sf.saxon.TransformerFactoryImpl"/>
              </component>
  • Now we need to edit cocoon/sitemap.xmap to enable the Saxon transformer. In the <map:transformers> section, add this below the other XSLT transformers:
          <map:transformer name="saxon" pool-grow="2" pool-max="32" pool-min="8"
          		     src="org.apache.cocoon.transformation.TraxTransformer">
          	    <use-request-parameters>false</use-request-parameters>
          	    <use-browser-capabilities-db>false</use-browser-capabilities-db>
          	    <xslt-processor-role>saxon</xslt-processor-role>
              </map:transformer>
  • Add a suitable match to the pipeline:
       <map:match pattern="*.xml">
         <map:generate src="text/{1}.txt" type="text"/>
         <map:transform type="saxon" src="xsl/tokenise-string-to-xml.xsl"/>
         <map:serialize type="xml"/>
       </map:match>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: