We extend the previous examples somewhat more.
<exercise xmlns:macro="http://www.mathdox.org/MathBook/Macro"
xmlns:j_x="jelly:xml"
xmlns:q="http://www.mathdox.org/MathBook/Query"
xmlns:mdf="http://www.mathdox.org/MathDox/Functions"
xmlns:c="jelly:core"
xmlns:x="jelly:xml"
xmlns:cont="http://www.mathdox.org/MathBook/Context"
xmlns:monet="http://monet.nag.co.uk/monet/ns"
xmlns:om="http://www.openmath.org/OpenMath"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xhtml="http://www.w3.org/2002/xhtml"
xmlns:mdu="jelly:org.mathdox.util.UtilLibrary">
<interaction id="one">
<mdu:random var="r" minimum="1" maximum="4"/>
<feedback>
<para>
We pick a random number:
</para>
</feedback>
<answer_map text="go">
<set name="test2">
<OMOBJ>
<OMS name="false" cd="logic1"/>
</OMOBJ>
</set>
<set name="test3">
<OMOBJ>
<OMS name="false" cd="logic1"/>
</OMOBJ>
</set>
<c:if test="false">
<set name="test2">
<OMOBJ>
<OMS name="true" cd="logic1"/>
</OMOBJ>
</set>
</c:if>
<c:if test="false">
<set name="test3">
<OMOBJ>
<OMS name="true" cd="logic1"/>
</OMOBJ>
</set>
</c:if>
<choose>
<when target="two">
<out name="test2"/>
</when>
<when target="three">
<out name="test3"/>
</when>
<otherwise target="one"/>
</choose>
</answer_map>
</interaction>
<interaction id="two">
<feedback>
<para>
... and this the second.
</para>
</feedback>
<answer_map text="back">
<interaction xref="one"/>
</answer_map>
</interaction>
<interaction id="three">
<feedback>
<para>
... and this the third.
</para>
</feedback>
<answer_map text="back">
<interaction xref="one"/>
</answer_map>
</interaction>
</exercise>
The main difference between this and the previous examples is the
<choose/> inside the
<answer_map/>.
If a <when/>-tag inside the
<choose/> contains the OpenMath symbol
<OMS name="true" cd="logic1"/>, the user will be taken to the interaction specified in the target attribute of the
<when/>.
The evaluation starts at the top and goes down the list of <when/>'s. If none of them contains a <OMS name="true" cd="logic1"/>, the user is taken to the interaction specified in the <otherwise/>-tag.
Another new tags in this example are <set/>
and <out/>, with which one can set variables, both as strings and as XML-objects, output them, respectively.
See the example running.