cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robby Pelssers" <>
Subject RE: Saxon extensions / using Spring application Context
Date Tue, 09 Mar 2010 16:58:08 GMT
I managed to find a nice workaround actually.

Somewhere in the pipeline I need to determine image width and height based on scanning someimage.eps
boxdimension properties

So when I get to the point where I want to generate 

<image href="someimage.eps" width="75" height="83"/>

I actually generate a jx-template 

<?xml version="1.0" encoding="UTF-8"?>
Author: Robby Pelssers

<xsl:stylesheet version="2.0" 
  exclude-result-prefixes="fn nxp">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
  <xsl:function name="nxp:getBoxDimensionWidthJexlExpression" as="xs:string">
    <xsl:param name="graphicId"/>
    <xsl:value-of select="concat('${datasheetBuilder.getBoxDimensionWidth(&quot;',
$graphicId, '&quot;)}')"/>
  <xsl:function name="nxp:getBoxDimensionHeightJexlExpression" as="xs:string">
    <xsl:param name="graphicId"/>
    <xsl:value-of select="concat('${datasheetBuilder.getBoxDimensionHeight(&quot;',
$graphicId, '&quot;)}')"/>
  <!--  this function generates the corresponding DITA image tag -->
  <xsl:function name="nxp:getImageTag">
    <xsl:param name="graphicId"/>
    <xsl:variable name="src" select="concat('servlet:shared:/tdm/graphic/', $graphicId,
'/', $figure_extension)"/>    
    <image href="{concat($graphicId, '.', $figure_extension)}" width="{nxp:getBoxDimensionWidthJexlExpression($graphicId)}"

  <!-- copy all nodes and attributes which are not processed by one of available templates
  <xsl:template match="@*|node()">
    <xsl:copy copy-namespaces="no">
      <xsl:apply-templates select="@*"/>


Which I use as my generator from the main pipeline:

      <map:match pattern="generateProductTopics">
        <map:generate src="cocoon:/generateProductTopics-step-6" type="jx"/> 
        <map:serialize type="xml"/>

So now I have the advantage of being able to call Beans from my Spring ApplicationContext
and do caching like below:

public class DatasheetBuilderImpl implements DatasheetBuilder {

	private ImageCache imageCache;
	public void setImageCache(ImageCache imageCache) {
		this.imageCache = imageCache;
	public ImageCache getImageCache() {
		return this.imageCache;
	/** Start of convenience methods **/
	public int getBoxDimensionWidth(String graphicId) {
		return getImageCache().getBoxDimension(graphicId).getWidth();
	public int getBoxDimensionHeight(String graphicId) {
		return getImageCache().getBoxDimension(graphicId).getHeight();	

I think it's a pretty cool solution (workaround) to get performance boosts in batch processing.

Kind regards,
Robby Pelssers

-----Original Message-----
From: Robby Pelssers [] 
Sent: Tuesday, March 09, 2010 4:41 PM
Subject: Saxon extensions / using Spring application Context

Hi all,

I know you can call static java methods from xslt and even construct new java objects.  But
that happens NOT to match my use case.

Short description of my use case:

I have a datasheetbuilder bean defined in my applicationContext:

  <bean id="datasheetBuilder" class="com.nxp.spider2.application.DatasheetBuilderImpl"
    <property name="spider" ref="spiderBean"/> 
    <property name="imageCache" ref="imageCache"/>      

What I would like to do is call methods on this bean from within transformers (xslt) in the
pipelines processing the original request.  

Has anyone an idea if this would be possible somehow and if so can you point me to some documentation
or explain how to accomplish this.

I can easily imagine this would be possible by writing a custom java transformer (not using
xslt) which has access to the applicationContext but this involves quite a bit of work so...

Kind regards,
Robby Pelssers

View raw message