<s1 title="XTP Hello, World">

<p>XSL is a pattern matching language like Prolog.  It looks at XML nodes one
by one and checks the stylesheet for matching patterns.  XSL uses XPath as
the pattern-matching language.  Like Prolog, each XSL "rule" has a match
pattern and an execution program, the template.</p>

<p>To use XTP, you need an XTP file and an XSL stylesheet.  XTP parses
the XTP files as HTML and then evaluates the HTML using the stylesheet.
Since XTP is a standard XSL processor, the following tutorials will
apply to any other XSL engine.  The main difference between XTP and
an XSL engine like Xalan, is that XTP will automatically compile
the page to a JSP page.  You can achieve the same effect with Xalan,
but it takes a little more work.

<p>The following example has a single template, matching any &lt;hello>
tag.  When the XSL engine evaluates a &lt;hello> tag it matches the rule
in the stylesheet.  In this case, it replaces the &lt;hello> with
"Hello, World".  The &lt;xsl:text> marks a text replacement.</p>

<example title='default.xsl'>
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

&lt;xsl:template match="hello">
  &lt;xsl:text>Hello, World&lt;/xsl:text>
&lt;/xsl:template>

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

<p>The following XTP file is first parsed as an HTML file and then
processed by the <var/default.xsl/> stylesheet.  As mentioned above,
the &lt;hello/> tag is replaced by "Hello, World".</p>

<example title='hello.xtp'>
My First Tag: &lt;hello/>
</example>
<results>
My First Tag: Hello, World
</results>

<p>This above example hides a few details, namely the default XSL rules.
XTP's parser automatically inserts the &lt;html> and &lt;body> elements,
but as you see, they're not included in the result.  If an XML node doesn't
match any stylesheet pattern, XSL applies a default rule.  The default rule
for elements recursively evaluates the element children, but does not copy
the element itself.  Text nodes are copied.  In the above example, the
default rules eat the &lt;html> and &lt;body> elements, evaluating the
children, but copy the "My First Tag: " text.</p>

<s2 title="StyleScript equivalent">

<p>Resin provides an alternate syntax for XSL.  XSL does not scan well; it's
hard to find templates and figure out what they're doing.  In other words, XSL can become a write-only language.  StyleScript aims at having the same
functionality of XSL, but making it more maintainable.</p>

<example title='default.xsl'>
$template(hello) &lt;&lt;Hello, World>>
</example>

</s2>

<s2 title="Summary">

<ul>
<li>XTP needs an XML file (the .xtp) and an XSL stylesheet.
<li><var/default.xsl/> is the default stylesheet.
<li><var/xsl:template/> matches an XML tag and replaces it with new XML.
<li>The XPath pattern <var/name/> matches a named element.
<li><var/&lt;&lt; ... >>/> describes the replacement XML in StyleScript.
<li>XTP stylesheets provide syntactic sugar to XSL stylesheets, but are
completely equivalent.
<li><var/$template(foo)/> expands to <var/&lt;xsl:template match="foo">/>.
<li><var/xsl:text/> returns verbatim text.
</ul>

</s2>
</s1>
