Skip to main content

Conditional value execution

Anatomy

<if value1="string" value2="string|regexp" func="=">
ixml
<elseif value1="string" value2="string|regexp" func="string">ixml</elseif>
<elseis var="var" type="type">ixml</elseis>
<else>ixml</else>
</if>

Description: The IF construct is a control flow structure that allows for conditional execution of code dependent on two values.

If the condition is true, the embedded code is executed. Otherwise, a series of embedded ELSEIF and ELSEIS statements is tested one by one. Only the first ELSEIF or ELSEIS statement that is found to be true will be executed. If none of the conditions are true, the embedded ELSE statement will be executed instead.

Attention:

Comparison of numeric values is always performed numerically regardless of the intrinsic data types.

Regular expression matches regard 'value1' as the subject and 'value2' as the pattern.

IF will propagate results into the context of its paternal statement.

Attributes

NameTypeDescriptionDefined By
value1stringValue to compare from if
value2string|regexpValue to compare to if
funcstringComparison function if

Children

elseif

Anatomy of Elsewise conditional value execution

<elseif value1="string" value2="string|regexp" func="string">ixml</elseif>

Attributes:

NameTypeDescription
value1stringValue to compare from
value2stringregexp
funcstringComparison function
elseis

Anatomy of Elsewise conditional type execution

<elseis var="var" type="type">ixml</elseis>

Attributes:

NameTypeDescription
varvarVariable name
typetypeType
else

Anatomy of Elsewise execution

<else>ixml</else>

Examples

Basic comparison

<set var="name">iXML</set>

<if value1="$name" func="=" value2="iXML">
<output>My name is iXML!</output>

<else>
<output>My name is not iXML!</output>
</else>
</if>

<!-- My name is iXML! -->

Multiple comparison

<set var="name">Steve Jobs</set>

<if value1="$name" func="=" value2="Bill Gates">
<output>My name is Bill Gates!</output>

<elseif value1="$name" func="=" value2="Steve Jobs">
<output>My name is Steve Jobs!</output>
</elseif>

<else>
<output>My name is not Bill Gates nor Steve Jobs!</output>
</else>
</if>

<!-- My name is Steve Jobs! -->

Regular expression match

<set var="name">iXML</set>

<if value1="$name" func="~" value2="/^I/i">
<output>My name starts with an I!</output>
</if>

<!-- My name starts with an I! -->