How XTP works
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
User's Guide
Reference
Tutorials

How it works
XTP Copy
Formatting
Link Rewriting
JSP tag libraries
User's Guide
User's Guide
XTP Copy

XTP (XML Template Pages) creates web pages from XML using XSL stylesheets.

The documentation for the specific tags is in the XSLT stylesheet section. This section describes how XTP works.

XTP lets web designers create active pages without changing the original text. It uses a separate XSLT 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 XSLT 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.

Blank Stylesheet Example
In this example, we're using a blank stylesheet. Even with a blank stylesheet, does something useful: it prints out all text, removing the tags.

hello.xtp
<TITLE>Hello, world</TITLE>

<H1>Hi, World!</H1>

<P>The hello, world example is simple.

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.

hello$9342.dom
<html>
  <head>
    <title>Hello, world</title>
  </head>

  <body>
    <h1>Hi, World!</h1>

    <p>The hello, world example is simple.</p>
  </body>
</html>

Next, 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.

  1. #document, process children
    1. <html>, process children
      1. <head>, process children
        1. <title>, process children
          1. "Hello, world", print to output
      2. <body>, process children
        1. <h1>, process children
          1. "Hi, World!", print to output
        2. <p>, process children
          1. "The hello, ...", print to output

hello$9342.html
Hello, world

Hi, World!
The hello, world example is simple.

Simple Page Template
'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 match='*'. When processes a node whose pattern matches nothing else, it will execute the copy action. The action copies the element (xsl:copy) and processes the children (xsl:apply-templates).

<xsl:template match='*|@*'>
  <xsl:copy>
    <xsl:apply-templates select='@*|*'/>
  </xsl:copy>
</xsl:template>

For the page template pattern, we use match='/html/body'. will execute the template in place of the body.

<xsl:template match='/html/body'>

  <!-- cyan background -->
  <body bgcolor='cyan'>

  <table width='100%'>

  <!-- left margin -->
  <tr><td width='240'></td>

  <!-- center column -->
  <td width='80%'>

  <!-- insert body contents -->


  <xsl:apply-templates/>


  <!-- copyright footer -->
  <hr>
  Copyright &copy; 1999 Caucho Technology

  </td></tr>
  </table>
  </body>

</xsl:template>

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.

<TITLE>Hello, world</TITLE>

<H1>Hi, World!</H1>

<P>The hello, world example is simple.

<html>
  <head>
    <title>Hello, world</title>
  </head>

  <body bgcolor='cyan'>

  <table width='100%'>
  <tr><td width='240'></td>
  <td width='80%'>

    <h1>Hi, World!</h1>

   <p>The hello, world example is simple.
   </p>

  <hr>
  Copyright &copy; 1999 Caucho Technology

  </td></tr>
  </table>
  </body>
</html>


User's Guide
User's Guide
XTP Copy
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.