|
![]() |
![]() XTP (XML Template Pages) creates web pages from XML using XSL stylesheets. The documentation for the specific tags is in the XSL stylesheet section. This section describes how XTP works. XTP lets web designers create active pages without changing the original text. It uses a separate XSL stylesheet to transform the original document into a fancy formatted document. Because the active stylesheet is separate from the passive content, XTP gives designers a tighter focus. When worrying about style, designers can concentrate on the stylesheet. When concentrating on content, designers can focus on the text. XTP makes the input file simpler: it can be plain old HTML. It separates the content (*.xtp) from the style (*.xsl). The tradeoff is that XSL stylesheets are slightly more complicated than JSP active pages. For JSP, scripts execute exactly where they're placed. XTP has to match HTML to script fragments using patterns. XTP works by matching stylesheet patterns to the input HTML, creating the result HTML following the pattern actions. XTP analyzing the input HTML into a structured HTML tree using the XML document object model. For each node, it finds the best pattern in the XSL and applies the action. The action prints to the output HTML.
In this example, we're using a blank stylesheet. Even with a blank stylesheet, Resin does something useful: it prints out all text, removing the tags.
Resin first reads in the XTP file, parsing it like an HTML file. It adds optional tags, like <html> and </p> and forces all HTML tags to be lower case.
Next, Resin starts its matching process at the top. Since the stylesheet is empty, it uses the default rules. The default rules say: process an element's children and print a text node's data.
Resin's XTP can create standard page layout: common backgrounds, navigation, headers and footers. This is a common use for any of the active content creation tools. This example adds two things to the default stylesheet. All elements are copied instead of ignored, and the body of the HTML gets a background and a margin. Copying elements is easy. The copy template matches all elements
For the page template pattern, we use
The translation follows the same order as in the blank stylesheet example. The body rule is used for the body and the copy rule is used for every other tag.
All by itself, the template example is useful. But here's something more interesting, creating a dynamic tag. In this case, we'll just create a simple counter. To use the counter tag, just add it to the XTP file.
Here's the addition to the stylesheet file. The xtp:directive.page, like the same directive for JSP, tells Resin to generate JavaScript for the stylesheet. The default is Java. Since the counter example is trivial with JavaScript and cumbersome with Java, we're using JavaScript.
The JavaScript code is between the xtp:expression tags. Resin will insert the value of the expression into the generated text. Similar to JSP, stylesheets also allow the xtp:scriptlet and xtp:declaration tags. The
|