<s1 title="Default Attributes with xsl:if">

<p>Often, elements should have a default attribute value if none is
specified in the XTP file.  An &lt;example> tag might have a default CSS
class of "example", but let the XTP change the default.  In a template,
xsl:if will conditionally produce XML depending on an XPath expression.

<p>The following example adds the class attribute to the table
depending on the class value in the &lt;box> element.  If the XTP file
specifies the class, the stylesheet will use it.  The the XTP file doesn't
specify the class, the stylesheet will use "example" as a default.</p>

<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;xsl: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>

<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="StyleScript">

<p>StyleScript's $if uses the test expression for its first argument.
If the expression is true, the block is used as a value.   If false,
the block after the $else will be used for the value.</p>

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

</s2>

<s2 title="Summary">

<ul>
<li><var/xsl:if/> evaluates conditionally.
<li><var/not(expr)/> negates a boolean.
</ul>

</s2>
</s1>
