<document>
  <header>
    <product>resin</product>
    <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>
    <localtoc/>

<s1 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"&gt;
  &lt;filter filter-name='xslt' filter-class='com.caucho.filters.XsltFilter'/&gt;

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

</s1>

<s1 title="The Source Files">

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

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

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

<s1 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&gt;
&lt;xsl:output media-type='text/html'/&gt;

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

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

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

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

</s1>
  </body>
</document>