cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lopke, Michael" <>
Subject RE: How might I do this in Cocoon?
Date Fri, 25 Feb 2005 22:42:28 GMT
Thanks Con.  :-)

-----Original Message-----
From: Conal Tuohy [] 
Sent: Friday, February 11, 2005 4:22 PM
Subject: RE: How might I do this in Cocoon?

Mike Lopke wrote:

> I have a java servlet that queries a database and produces xml.
> Part of this includes translating some of the data, like product 
> numbers, using a HashMap.  The HashMap is built from an xml 
> source and is very large.  Populating it takes a long time so I 
> set it up using a singleton class and a timer to provide an 
> update mechanism that wouldn't cause performance issues.
> I was wanting the same functionality using Cocoon but want 
> to avoid the performance issues.  Is there a transformer I can 
> use?  Should I consider writing one?  

We've done something similar - we have XML documents in a pipeline which
we transform based on a huge (1GB RAM) Topic Map. This is definitely a
singleton :-)

We used the JXTemplateTransformer, and I think it would also work in
your case.

Your sitemap would look like this:

	<map:generate type="sql" ... />

	<!-- transform sql resultset into a jxtemplate -->
	<map:transform src="xslt/sql-to-jxt.xsl"/>

	<!-- execute the resulting jxtemplate to query the hashmap -->
	<map:transform type="jx"/>
	<map:serialize ... />

So you just have to write this sql-to-jxt.xsl stylesheet, but this is
actually quite easy.

First, the JXTemplate you create should have a global variable
containing your hashmap: <jx:set var="myHashMap" value=" (this is where
you look up your singleton) "/> 

You can create this using an XSLT template like:
<xsl:template match="/">
		<!-- obtain the singleton hashmap -->
		<!-- (could use jx:parameter here and pass hashmap from
flow) -->
		<jx:set var="myHashMap" value="etc..."/>

Then you generate jxtemplate code to translate the Product Numbers.

If your data has this: <sql:productNumber>foo</sql:productNumber>

... then you probably want to transform it to something like this:

You would use an XSLT template like this:


(And use an XSLT identity template to copy all the other sql data
through the pipeline, unchanged)

Hope that helps!


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message