<s1 title="XSL Filter">

<p>XSL, the XML stylesheet language, simplifies creating a uniform
style for a site.  XSL 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>.  In this case, we're selecting the
xml.xsl stylesheet.</p>

<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>

<s2 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>

</s2>
</s1>
