Serif (XML Template Pages) enhances JSP pages with stylesheets. Sophisticated projects can split page formatting from the JSP-generated content. Splitting the graphic design from the JSP programming helps a web site in several ways:
Since XTP is standards-based, developers benefit from widely-available public documentation, tutorials and support. Stylesheets are written in the W3C standard XSL (XML Stylesheet Language) and produce JSP (Java Server Pages).
The following shows a simple example of formatting JSP using stylesheets. The stylesheet formats a custom tag,. The exclamation translates into the HTML and can be easily changed to any desired format.
Except for the formatting tags, the *.xtp file is a normal *.jsp file describing an HTML page. Unlike JSP which copies its content as raw text, XTP parses the HTML contents into an internal tree (the XML DOM). A more aggressive *.xtp could use XML but most will use XML only where useful. Expressions, scriptlets, and declarations work just as JSP pages.
For everything but, the stylesheet copies its input directly to the output. Using this technique, you can add tags as you develop them. So a project can incrementally benefit from XTP; you don't need to entirely redesign your site.
The XTP engine produces a standard JSP file as an intermediate form. The generated JSP will process the request. Since it's standard JSP, you can use any JSP or Servlet feature, including using custom JSP tags (although XSL tags are generally more efficient.)
Unless the XTP source or the stylesheet changes, the XTP engine will continue to use the compiled JSP page without additional stylesheet processing. So the XTP has the same performance of a JSP page, with the flexibility of the stylesheet.
By default, XTP pages are read in as HTML. Non-HTML tags are treated as XML, i.e. they're expected to have an end tag for every begin tag. By allowing HTML as a primary input format, XTP pages provide a smooth transition path. Sites don't need to transform every page to XML to take advantage of XTP's formatting.
Pages can also be written in strict XML. If the page begins with, it will be read as strict XML. New sites may choose to design using a strict XML base.
Selecting in the XTP file
XTP pages generally select their stylesheet using the standardprocessing instruction. If no stylesheet is selected, the XTP page will use .
Stylesheet Search Path
When building libraries of stylesheets, using the Java classpath has several advantages. It's naturally arranged in a path, it's familiar, and it is well supported by the servlet engines.
The request parameterselects the stylesheet for the XTP page. If set, it overrides the value specified in the XTP page. A filter servlet can set to process the same page with different styles. For example, a User-Agent filter could select a different stylesheet for a Palm client or for a printable version of the page.
The XTP engine can setvariables taken from the servlet request. Stylesheets can use these variables, like , to create several web pages out of a single source XTP. A section, for example, might only be displayed if it matches the .
Stylesheets must useto use servlet parameters. Unless the stylesheet declares its parameters, XTP will not pass the values to the stylesheet.
A sample XTP file might look like: