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="/">
        <jx:template>
                <!-- obtain the singleton hashmap -->
                <!-- (could use jx:parameter here and pass hashmap from
flow) -->
                <jx:set var="myHashMap" value="etc..."/>
                <xsl:apply-templates/>
        </jx:template>
</xsl:template>

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:
<sql:productNumber>#{$myHashMap/foo}</sql:productNumber>

You would use an XSLT template like this:

<xsl:template match="sql:productNumber/text()">#{$myHashMap/<xsl:value-of
select="."/>}</xsl:template>

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

Hope that helps!

Con

<<attachment: winmail.dat>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to