[xsl] Still Alive?

Subject: [xsl] Still Alive?
From: Eric Berry <elberry@xxxxxxxxx>
Date: Thu, 27 Jan 2005 13:17:41 -0800
I'm not sure if this mailing list is still active. I am truly hoping that it is.

I am having some trouble using XSLT in my web application.

More specifically I'm having trouble using Java during the translation
process. I have worked with XSL quite a bit for this project and I've
had to use little static Java helpers to perform really complex
calculations and conditionals. However, a situation has come up where
life would be a lot easier if I could have a persistent Java Object
during Translation.

The situation.
I have an XML document with 3 large nodes under the root.

<es-feed>
   <events />
   <performers />
   <venues />
</es-feed>

My Application is only concerned with the events node, however the
events need specific information provided within the performers and
venues nodes.

My XSLT file looks like:

<xsl:template match="/">
   <general-feed>
      <xsl:apply-templates select="performers" />
      <xsl:apply-templates select="venues" />
      <xsl:apply-templates select="events" />
   </general-feed>
</xsl:template>

What I want to do is create a global variable that is a Java Object,
and then I want to use this Java object to store the required
information about performers and venues so that I can access it very
quickly when translating the events node.

A cut down version of the entire XSL file would look something like this:
<xsl:template match="/">
	<xsl:variable name="eventHolder" select="java:EventHolder.new()"/>
   <general-feed>
      <xsl:apply-templates select="performers" />
      <xsl:apply-templates select="venues" />
      <xsl:apply-templates select="events" />
   </general-feed>
</xsl:template>
<xsl:template match="performers">
	<xsl:for-each select="performer">
		<xsl:variable name="id" select="@id" />
		<xsl:variable name="name" select="name" />
		<xsl:value-of select="eventHolder.holdPerformerName($id, $name)" />
	</xsl:for-each>
</xsl:template>
<xsl:template match="venues">
	<xsl:for-each select="venue">
		<xsl:variable name="id" select="@id" />
		<xsl:variable name="name" select="name" />
		<xsl:value-of select="eventHolder.holdVenueName($id, $name)" />
	</xsl:for-each>
</xsl:template>
<xsl:template match="events">
		<events>
	<xsl:for-each select="event">
		<xsl:variable name="performerID" select="performer-id" />
		<xsl:variable name="venueID" select="venue-id" />
			<event>
				<name><xsl:value-of select="name"/></name>
				<performer-name><xsl:value-of
select="eventHolder.getPerformerName($performerID)"
/></performer-name>
				<venue-name><xsl:value-of
select="eventHolder.getVenueName($venueID)" /></venue-name>
			<event>
	</xsl:for-each>
		</events>
</xsl:template>

I can create the variable easily and it works. However I get errors
whenever I try to access one of the methods.

Perhaps there is a better way to do this, and I'd appreciate any help
anyone can give me.

Thanks,
Eric

Current Thread