Conditional Processing
Input Example:
<declare name="v" initial-value="1"/>
<if-var name="v" match="1*">
<_xml_>matched</_xml_>
</if-var>
<if-var name="v" not-match="1*">
<_xml_>not matched</_xml_>
</if-var>
<if-var name="v" match="[0-9]+" match-type="regex">
<_xml_>regex matched</_xml_>
</if-var>
<if test="$v > 0">
<_xml_>xpath matched</_xml_>
</if>
Output Example:
<_xml_>matched</_xml_>
<_xml_>regex matched</_xml_>
<_xml_>xpath matched</_xml_>
<declare name="v" initial-value="1"/>
Input Example:
<param name="v" value="1"/>
<if-var name="v" match="1*" realm="param">
<_xml_>matched</_xml_>
</if-var>
<option name="tmp_dir" value="/tmp"/>
<if-var name="tmp_dir" match="1*" realm="option">
<_xml_>not_matched</_xml_>
</if-var>
Output Example:
<param name="v" value="1"/>
<_xml_>matched</_xml_>
<option name="tmp_dir" value="/tmp"/>
Choose statements can involve multiple types of tests. The content of the first successful <incode>when</incode> or <incode>when-var</incode> test will be processed. If none is successful, the <incode>otherwise</incode> content, if it exist, is processed.
Input Example:
<declare name="v" initial-value="v"/>
<choose>
<when-var name="v" match="v1">
<bad/>
</when-var>
<when-var name="v" match="v2"/>
<when-var name="v" match="v">
<good1/>
</when-var>
</choose>
<choose>
<when test="contains($v, 'w')">
<bad/>
</when>
<when-var name="v" not-match="v"/>
<when test="$v = 'v'">
<good2/>
</when>
</choose>
<choose>
<when-var name="v" match="v1">
<bad/>
</when-var>
<when-var name="v" match="v2"/>
<when-var name="v" match="v3"/>
<otherwise>
<good3/>
</otherwise>
</choose>
Output Example:
<good1/>
<good2/>
<good3/>
<declare name="v" initial-value="v"/>
Pass the value of a CGI parameter to an option while controlling its range and assigning a default in case the range is not satisfied:
Input Example:
<declare name="query.num-total"/>
<param name="num" value="500"/>
<set-var name="query.num-total">
<choose>
<when-var name="num" realm="param" match="^[0-9]?[0-9]?[0-9]$" match-type="regex">
<value-of realm="param" name="num"/>
</when-var>
<otherwise>200</otherwise>
</choose>
</set-var>
Output Example:
<param name="num" value="500"/>
<declare name="query.num-total" initial-value="500" modified="modified"/>
To proceed with this tutorial, click Templates.