I've taken out as much of my application specific stuff as possible. Here are the
basic calls.
private Templates template_;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
//for storing a compiled and resuseable style sheet
TransformerFactory factory = TransformerFactory.newInstance();
template_ = factory.newTemplates(new StreamSource("c:\\style.xsl"));
}
catch (Exception ex)
{
//exception handling here
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
try
{
//there are some application specific things here.
//the primary thing to note is that you need a Document.
Document appResponse = application_.processRequest(
user, userRequest);
Transformer transformer = template_.newTransformer();
//otherwise it is UTF8
transformer.setOutputProperty("encoding", "iso-8859-1");
transformer.transform(
new DOMSource(appResponse),
new StreamResult(response.getWriter()));
}
catch (Exception ex)
{
//exception handling here
}
}
----------
From: J. David Eisenberg
Sent: Monday, August 13, 2001 11:54 AM
To: [EMAIL PROTECTED]
Subject: Precompiled stylesheet example
I am trying to find a lightweight sample that shows how to read an XSLT
file, "precompile" it once, and then use it over and over again with
different XML files. Such a sample in a servlet context would be faboo.
I've looked through the archives but have only found references to
problems, or messages whose character set is incompatible with my server,
but no actual code.
Sorry if this is the 10**9th such request that's come through this board.
---
J. David Eisenberg http://catcode.com/
<<application/ms-tnef>>
