<s1 title="Copying nodes and attributes">

<p>Stylesheets can use xsl:copy to copy nodes from the XTP file to
the generated HTML.  The most common use of xsl:copy creaes a default
rule to copy the input to the output, i.e. the identity transformation.

<p>In the previous examples, the default rule omitted
unknown elements.  For most XTP pages, a better default rule copies
the input to the output.  That way the page can use XTP as little
as it wants and mix and match JSP and HTML with custom tags.

<p>The following example creates a default identity pattern and a
single custom tag.  The match pattern "*|@*" matches any element (the "*")
and any attribute (the "@*").  The vertical bar is a union operator.
The node is copied using xsl:copy and the contents apply the
stylesheet recursively.

<p>xsl:apply-templates has an optional select pattern.  The selected
nodes will have the stylesheet recursively applied.  The default
pattern selects all children nodes.  The identity template needs to
select children nodes and attribute nodes.  "node()" selects any child
nodes and "@*" selects attributes.</p>

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

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

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

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

<example title='hello.xtp'>
Testing &lt;font color="red">&lt;hello/>&lt;/font>
</example>

<results>
&lt;html>
&lt;body>
Testing &lt;font color="red">Hello&lt;/font>
&lt;/body>
&lt;/html>
</results>

<s2 title="StyleScript">

<p>The StyleScript equivalent for $apply-templates uses the select attribute as
its first parameter.  $copy acts like any typical element.</p>

<example title='default.xsl'>
$template(*|@*) &lt;&lt;
  $copy &lt;&lt; $apply-templates(node()|@*); >>
>>

$template(hello) &lt;&lt;Hello>>
</example>

</s2>

<s2 title="Summary">

<ul>
<li>The XPath pattern <var/*/> matches any element.
<li>The XPath pattern <var/@*/> matches any attribute.
<li>The XPath pattern <var/a|b/> matches pattern <var/a/> or <var/b/>
<li><var/xsl:copy/> copies XML nodes to the output.
<li><var/xsl:apply-templates/> can select the nodes to evaluate.
<li>XTP pages are parsed as HTML, automatically expanding optional tags, like
<var/html/> and <var/body/>.
<li>Specific templates override general templates.
<li>Later templates override earlier ones.
<li><var/$copy/> expands to <var/xsl:copy/>
<li><var/$apply-templates(foo)/> expands to <var/&lt;xsl:apply-templates select="foo"/&gt;/>
</ul>

</s2>
</s1>
