Saxon is a great XSLT engine and supports XSLT 2.0. I normally use it for almost of all my transformations. But getting it to work in Cocoon 2.2 needs some steps. We will see which steps are necessary to get Saxon working in a Cocoon 2.2 block.
We first must have a Cocoon block to which we will add Saxon support. Next we create the directory src/main/resources/META-INF/cocoon/avalon
. In this directory we can add component definitions, which are used by our block. In this directory we add the file cocoon-core-xslt-saxon.xconf
. The contents of the file contains the Saxon transformer definition:
<?xml version="1.0" encoding="UTF-8"?> <components> <component 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> </components>
Notice we use /saxon
at the end of value for the role attribute and we need this name for further configuration. We now create another file in the src/main/resources/META-INF/cocoon/avalon
directory with the name sitemap-transformers-saxon-transformer.xconf
. In the file we add a transformer definition to reference the Saxon transformer component. Notice the xslt-processor-role
must be saxon
like we defined in our component definition:
<map:components xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:transformers> <map:transformer name="saxon" src="org.apache.cocoon.transformation.TraxTransformer"> <xslt-processor-role>saxon</xslt-processor-role> </map:transformer> </map:transformers> </map:components>
Now we only need to a dependency to our pom.xml
to include the Saxon library in our application classpath:
<dependency> <groupId>net.sf.saxon</groupId> <artifactId>saxon</artifactId> <version>8.7</version> </dependency>
And now we can use the Saxon transformation in our Cocoon 2.2 block.