XTP Copy
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
How it works
User's Guide
Formatting

For most XTP pages, the default XSLT transormation you want is to copy the input into the output. Your XTP pages can be almost identical to JSP pages and just use XSLT to eliminate repetitious error-prone patterns.

XTP transforms XML or HTML documents into a XML or HTML output. In other words, it's an XML transformation. So each XTP page has four parts:

  1. The input XML (the XTP file)
  2. The transformation stylesheet (the XSL file)
  3. The generated JSP
  4. The generated output (the result of executing the JSP)

The easiest transformation is the identity transformation. The following stylesheet copies the input into the output.

default.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <!-- make sure '<' is not printed as '&lt;' -->
  <xsl:output disable-output-escaping='true'/>

  <!-- copy input to output -->
  <xsl:template match='*|@*'>
    <xsl:copy>
      <xsl:apply-templates select='node()|@*'/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Each template contains a match pattern and a replacement tree. The match pattern is an XPath expression. In the above example, the match pattern *|@* matches any element and any attribute. The replacement xsl:copy copies the current node and calls xsl:apply-templates to recursively evaluate any children of the current node.

You can put default.xsl in the same directory as the xtp file, or you can put in WEB-INF/xsl, or you can put it in the classpath like WEB-INF/classes. The last option is useful if you want to create a jar of useful stylesheets and beans.

Your XTP page may look something like:

test.xtp
<h1>My test</h1>

Adding: 2 + 2 = <%= 2 + 2 %>

The generated JSP is identical to the input, and the generated HTML just executes the JSP.

<h1>My test</h1>

Adding: 2 + 2 = 4


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