One strategy for creating model - view -controller structures is to use a "thin" servlet as the controller, a backend class as the model or interface to the model, and an XSL transformer class as the view component.
For example, the servlet can simply determine the client's intentions -- in a large case statement, a sequence of if-then-else statements, or some other similar construct -- and then call the appropriate method in a backend class that represents the outer layer of the model. Once the model performs the requested action, it returns the results as an XML string to the servlet. The servlet then passes this result XML string to a view class that uses an XSL style to transform it into HTML that is returned to the client.
This lessons works through and discusses this architecture.
Architecture
XML is very general and can be used in many different ways. Here, an architecture is discussed that conforms to the general model-view-controller architecture and is well-suited for form-based interaction with a semantic object, such as a DBMS application.
XML Document
A simple example XML document is provided here.
XSL Stylesheet
A simple example XSL stylesheet is provided that can be used with the example XML document, listed above.
XML Transform Class
An XSL translator is shown as a Java class, suitable for use as the view component of a Servlet controller. It takes a simple XML document and XSL stylesheet and produces HTML output that is written to the Servlet's ServletOutputStream.
XSL Translation Application
A minimal XSL translator is shown as a Java application. It takes a simple XML document and XSL stylesheet and produces HTML output.
XSL Translation Servlet
The XSL Translation application, listed above, is rewritten as an independent Java Servlet.
Using Table-Formatted Forms as User Interface
A more realistic example is discussed. It is a form for obtaining user input, rendered as a two-column table. HTML for the form is shown, which could be produces using an XSL stylesheet.