<document>
  <header>
    <product>resin</product>
    <resin-2.0>$resin/java_tut/xsl-filter.xtp</resin-2.0>
    <title>XSLT Filter</title>
    <description>
      <p>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.</p>

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

  <body>
    <summary/>

<section title='web.xml Configuration'>

<p>The filter must be configured in the web.xml:</p>

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

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

</section>

<section title='The Source Files'>

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

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

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

<example title='xml.xsl'>
&lt;xsl:stylesheet>

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

&lt;/xsl:stylesheet>
</example>
</section>

<section title='HTML generation'>

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

<example title='html.xsl'>
&lt;xsl:stylesheet>
&lt;xsl:output media-type='text/html'/>

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

&lt;xsl:template match='count'>
Count: &lt;xsl:apply-templates/>&lt;br/>
&lt;/xsl:template>

&lt;xsl:template match='title'/>

&lt;/xsl:stylesheet>
</example>

</section>
  </body>
</document>
