CSci 4608 Principles of Web Programming, UMM: XSL processing in a servlet.

The path to the xml and xsl files is relative to jakarta-tomcat-5.0.30/bin. At this point the files are right in this directory. In general, this is not a good idea, creating a subfolder would be better.

import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ExampleServlet extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException	       
        PrintWriter out = response.getWriter();

	String XMLSource = "food.xml";
	String XSLStylesheet = "food.xsl";
	try {
	// Instantiate a TransformerFactory.
	javax.xml.transform.TransformerFactory tFactory = 

	// Use the TransformerFactory to process the stylesheet Source and
	// generate a Transformer.
	javax.xml.transform.Transformer transformer = tFactory.newTransformer

	// Use the Transformer to transform an XML Source and send the
	// output to a Result object.

	} catch (javax.xml.transform.TransformerException e) {
	    System.out.println("Transformer exception " + e);

CSci 2101 home page

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.