Servlet and XSL

Hello
I’m loking for a simple example of the presentation XML data(from Tamino) in Java servlet. XML data should be formatted with XSL. XSL sheet must be placed in String (or String [])variable or in Tamino data.

I’ll be gratful for examples and suggestions.

Best regards
Leszek

Here comes an example of using Tamino with Servlets and xerces:

xmlparser myParser = new xmlparser();
PrintWriter out = new PrintWriter(resp.getOutputStream());
String query = “…taminoQuery…”;
String xslDatei = "… name of xsl-File…"
String ErrorMsg=myParser.ParseXMLDocument(query, xslDatei, out);

class xmlparser contains method ParseXMLDocument:

import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;

public String ParseXMLDocument ( String XML, String XSL,PrintWriter myPrintWriter ) {
try {
processor.process(new XSLTInputSource(XML), new XSLTInputSource(XSL),
new XSLTResultTarget(myPrintWriter));
return “”;
}
catch (Exception e) { processor.reset(); return e.toString(); }

Hope it helps!
Uli Licker

Hello Uli,
I read the code that you posted but I couldnt find the xmlParser class in the Xerces API, and there was no method called parseXMLDocument(). Will otherparsers like DOM builder work?
Also once the transformation is complete, how does the printwriter() work? I couldnt understand…Please help me. Thanks a lot,
Best Regards,
Parth B

parthb: I don’t think you’ve understood the code that Uli posted, the class xmlParser was a user-written class not one supplied with Xalan or Xerces. However, there are a lot of gaps in Uli’s code (things he hasn’t shown), and I suggest you don’t start from here. There are examples of how to invoke Xalan from a servlet in the Xalan documentation; the only thing that’s special about doing it in Tamino is that the source document (and perhaps the stylesheet) are read by means of URIs that incorporate Tamino queries.