XSLT Filter
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
JAXP
User's Guide
Reference
FAQ
Scrapbook

XML Path Language (XPath)
XSLT-lite examples
XSLT Filter
XSLT-lite examples
User's Guide
Reference

XSLT filters can be applied to the output of a JSP page or a Servlet. XSLT simplifies creating a uniform style for a site. XSLT converts XML to HTML or XML or WAP. It's easy to create different output depending on the browser. Just choose another stylesheet. The example below creates HTML or XML results from the same JSP.

The JSP page creates a simple XML file. It tells Resin to use XSL filtering by setting the contentType to x-application/xslt.

  1. web.xml Configuration
  2. The Source Files
  3. HTML generation

web.xml Configuration

The filter must be configured in the web.xml:

<web-app xmlns="http://caucho.com/ns/resin">
  <filter filter-name='xslt' filter-class='com.caucho.filters.XsltFilter'/>

  <filter-mapping url-pattern='*.jsp' filter-name='xslt'/>
</web-app>

The Source Files

test.jsp
<%@ page session=false contentType='x-application/xslt' %>
<?xml-stylesheet href='xml.xsl'?>
<top>
  <title>Hello, world</title>
  <count><%= 1 + 1 %></count>
</top>

Stylesheets belong in WEB-INF/xsl. If no stylesheet is selected, Resin will use default.xsl.

The xml.xsl stylesheet just copies the input to the output. Many stylesheets will use this rule as a default rule.

xml.xsl
<xsl:stylesheet>

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

</xsl:stylesheet>

HTML generation

The HTML example is slightly more complicated. When it matches a top, it generates the HTML header information. The count tag just writes out the count.

html.xsl
<xsl:stylesheet>
<xsl:output media-type='text/html'/>

<xsl:template match='top'>
<html>
<head>
<title><xsl:value-of select='title'/></title>
</head>
<body bgcolor='white'>
<h3><xsl:value-of select='title'/></h3>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match='count'>
Count: <xsl:apply-templates/><br/>
</xsl:template>

<xsl:template match='title'/>

</xsl:stylesheet>


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