You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dave Ford <df...@smart-soft.com> on 2001/05/06 22:44:16 UTC

xsl jar Version Conflict

Problem:

Suppose one wants to use xsl transforms in a web-app and the web-app must be
servlet-engine-independent. As it turns out, this is no easy task. Why?
Because most servlet engines ship with a built-in xml library. Your servlet
can, if desired, use this built-in xml library. The problem is, your servlet
is no longer servlet-engine-independent because you are relying on the
servlet-engine's built-in xml library. And not ALL servlet-engines have a
built-in xml library. And even if they did, there is no guarantee that it
would be the same version as that required by your servlet.

One possible solution might be to ship your preferred xml-library as part of
the web-app. That, after all, is why WEB-INF/lib was invented.
Unfortunately, this won't work. Why? Because the servlet-engine's built-in
xml parser will probably conflict with the one you ship with your web-app
(i.e. the one in WEB-INF/lib).

Solution:

After struggling with this problem for a week or so, I finally came up with
a solution (actually I got the idea from my friend Jordan and the people on
this mailing list): Use a separate class loader to load your xml libraries.
Thus, I created a servlet called XSLServlet. This can be dropped in to any
web-app to provide servlet-engine-independent xsl support.

It works like this:

http://yourhost/yourwebapp/somexmlfile.xml?xsl=/somestylesheet.xsl

Three things to note: 1. the style sheet path is web-app relative. 2. you
must add a servlet-mapping entry to your web.xml file for this to work. 3.
Place the 3 jaxp xml jar files into your web-app in folder called
c:\MyWebApp\lib (substitute your web-app's path)

I thought this might be useful to others, so I have attached the servlet to
this e-mail.

Dave Ford
Smart Soft - The Java Training Company
http://www.smart-soft.com