Conditional Processing
DPML provides two conditional statements
an if-then-else and a choose
statement.
if-then-else
The structure of the
if
statement is:
<if>
<cond>
<instr />
</cond>
<then>
<instr />
</then>
<else>
<instr />
</else>
</if>
When program flow enters the <if>
block
the instructions within the
<cond>
block are executed first.
A resource identified by the URI this:cond
is associated
with the
<cond>
block.
The instructions within a <cond>
block must,
at some point before the end of the block, assign a
boolean to this:cond.
The IAspectBoolean associated this:cond
is evaluated as the result of the
<cond>
block and the conditional branch is performed.
If the resource identified by this:cond
represents true
the
<then>
block is executed otherwise the
<else>
block
is executed.
The following example program illustrates how to set the resource this:cond
to true.
Copy and paste this program into the
DPML Playpen
to see the results and experiment
with the conditional structure.
<idoc>
<if>
<cond>
<instr>
<type>copy</type>
<operand>
<b>t</b>
</operand>
<target>this:cond</target>
</instr>
</cond>
<then>
<instr>
<type>copy</type>
<operand>
<html>the value is true</html>
</operand>
<target>this:response</target>
</instr>
</then>
<else>
<instr>
<type>copy</type>
<operand>
<html>the value is false</html>
</operand>
<target>this:response</target>
</instr>
</else>
</if>
</idoc>
This example uses a
canonical document
for the boolean value.
NetKernel will automatically transrept the canonical XML boolean document into an
IAspectBoolean representation with the appropriate value
when it is set to the resource this:cond
.
choose
The structure of the
choose
statement is:
<choose>
<cond>
<instr />
</cond>
<then>
<instr />
</then>
<cond>
<instr />
</cond>
<then>
<instr />
</then>
....
<else>
<instr />
</else>
</choose>
When program flow enters the <choose>
block the
<cond>
blocks are executed in document order until one evaluates to
true.
When a true condition is found the following
<then>
block is executed and
all subsequent blocks are ignored.
If none of the
<cond>
blocks evaluates to true
then an existing
<else>
block is executed.