<s1 title="Default Attributes with Filter Patterns">

<p>XPath filter patterns can simplify default attributes.  Instead of using
some sort of <var/if/> pattern, an XPath pattern can match elements with
a specific attribute.  In the CSS class attribute example, the
stylesheet can have separate templates for an example with a class
attribute and one without it.

<p>An XPath filter looks like <var/foo/>[<var/test/>].  The test
expression is evaluated with <var/foo/> as the context node.  The
following example uses <var/example/>[<var/@class/>] to match only
examples with class attributes.

<p>The test expression can be any XPath expression.  If it's a node
expression like @class, the filter will match if it can select any
matching node.</p>

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

&lt;xsl:template match="example">
  &lt;table class="example">
    &lt;tr>
      &lt;td>
        &lt;xsl:apply-templates/>
      &lt;/td>
    &lt;/tr>
  &lt;/table>
&lt;/xsl:template>

&lt;xsl:template match="example[@class]">
  &lt;table class="{@class}">
    &lt;tr>
      &lt;td>
        &lt;xsl:apply-templates/>
      &lt;/td>
    &lt;/tr>
  &lt;/table>
&lt;/xsl:template>

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

<p>In the example stylesheet, an &lt;example> tag will match the
second template if it has a class attribute.  It will match the first
template if it has no class attribute.

<p>The example XTP does not specify class, so the stylesheet will
use "example" as the default class.</p>

<example title='hello.xtp'>
&lt;example>
This is an example.
&lt;/example>
</example>
<results>
&lt;table class="example">
&lt;tr>
  &lt;td>This is an example&lt;/td>
&lt;/tr>
&lt;/table>
</results>

<s2 title="Summary">

<ul>
<li><var/foo/>[<var/test/>] is an XPath filter pattern.
<li>Filter patterns match both the path and the filter expression.
<li>If the filter is a selection path, it matches if it selects any node.
</ul>

</s2>
</s1>

