<s1 title="Default Attributes with XPath if()">

<p>Since xsl:if can be cumbersome, Resin adds a special XPath
function <var/if()/>.  Although if() is not part of the XPath standard,
it's expected that the next version of the standard will add it.

<p><var/if()/> is like the Java conditional expression
<var/test&nbsp;?&nbsp;true&nbsp;:&nbsp;false/> pattern.  In XPath, it
looks like <var/if(test,true,false)/>.  Using if() can simplify
stylesheets dramatically, especially in combination with attribute
value templates.  The
following is a simplification of the previous stylesheet using "example"
as the default attribute value.</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="if(@class,@class,'example')">
    &lt;tr>
      &lt;td>
        &lt;xsl:apply-templates/>
      &lt;/td>
    &lt;/tr>
  &lt;/table>
&lt;/xsl:template>

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

<p>Notice that the 'example' value needs to be quoted, otherwise it
would be interpreted as selecting an element value.  The following XTP
specifies a different class for the example.  Often, though, it's a
good idea to stick with meaningful tags like &lt;example> and leave
formatting questions like the CSS class to the stylesheet.  In that case,
you can use attributes to select different templates.</p>

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

<s2 title="Summary">

<ul>
<li><var/if(expr,true_expr,false_expr)/> is a conditional expression.
</ul>

</s2>
</s1>
