<title>XTP: xsl:if</title>

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

&lt;xsl:template match="example">
  &lt;table>
    &lt;xsl:attribute name="class">
      &lt;xsl:if test="@class">
        &lt;value-of select="@class"/>
      &lt;/xsl:if>
      &lt;xsl:if test="not(@class)">example&lt;/xsl:if>
    &lt;/xsl:attribute>
    &lt;tr>
      &lt;td>
        &lt;xsl:apply-templates/>
      &lt;/td>
    &lt;/tr>
  &lt;/table>
&lt;/xsl:template>

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

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

<section title="StyleScript">

<example title='default.xsl'>
$template(example) &lt;&lt;
&lt;table>
  $attribute("class") <<$(if(@class,@class,"example"))>>
&lt;tr>
  &lt;td>
    $apply-templates();
  &lt;/td>
&lt;/tr>
&lt;/table>
>>
</example>

</section>

<section title="Summary">

<ul>
<li>Tags in stylesheets are parsed, not raw text.  So you can add attributes
to elements.
<li><var/$attribute(my-name)/> adds an attribute to an element.
<li><var/$attribute(my-name)/> expands to <var/xsl:attribute name="my-name"/>.
<li>The XPath pattern <var/if(test,if-true,if-false)/> selects a value
based on a boolean.
<li><var/if(test,if-true,if-false)/> is a Resin extension.
<li><var/xsl:if/> evaluates conditionally.
</ul>

</section>
