else if
Syntax
if (expression) {
/* code */
} else if (expression) {
/* code */
}/* Syntax with optional parentheses added in SLAX version 1.3 */
if expression {
/* code */
} else if expression {
/* code */
}Description
Include instructions that are processed if the expression defined in the preceding
if statement evaluates to FALSE and the expression
defined in the else if statement evaluates to TRUE.
You can include multiple else if statements. However, the processor
only executes the instructions contained in the first else if statement
whose expression evaluates to TRUE. The processor ignores all
subsequent else if statements.
Attributes
expression |
Specifies the expression to evaluate. Starting in SLAX version 1.3, the parentheses enclosing the statement expression are optional. |
SLAX Example
The following example checks for a description at the current context. If it does not exist, the script then checks for a description at the parent level. If there is no description, the script prints the "no description found" message.
var $description2 = {
if (description) {
expr description;
} else if (../description) {
expr ../description;
} else {
expr "no description found";
}
}XSLT Equivalent
<xsl:variable name="description2">
<xsl:choose>
<xsl:when test="description">
<xsl:value-of select="description"/>
</xsl:when>
<xsl:when test="../description">
<xsl:value-of select="../description"/>
</xsl:when>
<xsl:otherwise>unknown</xsl:otherwise>
</xsl:choose>
</xsl:variable>Usage Examples
Release Information
Statement introduced in SLAX version 1.0.
Support for syntax with optional parentheses added in SLAX version 1.3.