Advanced Control Flow - JPath
JPath Logic Sheet
Samples of this Logic Sheet are avaliable in the XSP implementation of the petstore block
The JPath tags are defined in the namespace
The if tag allows the conditional execution of its body according to value of its test attribute:
<if test="XPathExpression"> body </if>
<jpath:if test="cart/numberOfItems = 0"> Your cart is empty </jpath:if>
The choose tag performs conditional block execution by its embedded when sub tags. It renders the body of the first when tag whose test condition evaluates to true. If none of the test conditions of its nested when tags evaluate to true, then the body of its otherwise tag is evaluated, if present:
<choose> <when test="XPathExpression"> body </when>+ <otherwise> body </otherwise>? </choose>
<choose> <when test="not(user/loggedIn)"> You're not logged in </when> <otherwise> You're already logged in </otherwise> </choose>
The value-of tag evaluates an expression and outputs the result of the evaluation:
The for-each tag allows you to iterate over a collection of objects:
<for-each select="XPathExpression"> body </for-each>
When using XPath expressions within for-each the current element is the context node and can be referenced with XPath dot operator:
<for-each select="cart/cartItems[position() <= $count]"> <td><value-of select="./productId"></td> </for-each>
The continuation tag returns the id of the current web continuation of your Flowscript. You can refer to previous continuations by supplying the optional level attribute. Zero is the current level, -1 refers to the previous continuation, and so on.
The set-lenient tag switch the lenient setting of jxpath. By default it is set to false. If set to true, xpaths that don't point to an object or a set of them will return null (Instead of that annoying exception). Saves all the checking if you can accept nulls and are sure there are no typos.
If the tag contains child elements it will scope the setting for the enclosed elements, otherwise it is a global setting. You can't nest <jpath:set-lenient> tags.