blob: d986e89e81457780f7cc3486483275c26f505a8e [file] [log] [blame]
<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "../../dtd/document-v10.dtd">
<document>
<header>
<title>Advanced Control Flow</title>
<authors>
<person name="Christopher Oliver" email="coliver@apache.org"/>
<person name="Ovidiu Predescu" email="ovidiu@apache.org"/>
</authors>
</header>
<body>
<s1 title="JPath Logic Sheet">
<p>
The JPath Logic Sheet is an <link href="../xsp/index.html">XSP</link> logic sheet that allows
you to access data from a Cocoon Flowscript in an XSP page and inject it into a Cocoon
pipeline. It provides a set of tags (similar to the those defined by
<link href="http://www.w3.org/TR/xslt">XSLT</link>) that allow you to iterate over Java
collections (and Java or JavaScript arrays) and to test for the presence of optional or
alternate bean properties. It is based on
<link href="http://jakarta.apache.org/commons/jxpath">Apache JXPath</link>.
</p>
</s1>
<s1 title ="Tags">
<p>The JPath tags are defined in the namespace</p>
<source>http://apache.org/xsp/jpath/1.0</source>
<s2 title ="if">
<p>The <code>if</code> tag allows the conditional execution of its body according to value of its <code>test</code> attribute:</p>
<source>
&lt;if test="XPathExpression"&gt;
body
&lt;/if&gt;
</source>
<p>Example:</p>
<source>
&lt;jpath:if test="cart/numberOfItems = 0"&gt;
Your cart is empty
&lt;/jpath:if&gt;
</source>
</s2>
<s2 title ="choose">
<p>The <code>choose</code> tag performs conditional block execution by its embedded
<code>when</code> sub tags. It renders the body of the first <code>when</code> tag whose
<code>test</code> condition evaluates to true. If none of the <code>test</code> conditions
of its nested <code>when</code> tags evaluate to <code>true</code>, then the body of its
<code>otherwise</code> tag is evaluated, if present:</p>
<source>
&lt;choose&gt;
&lt;when test="XPathExpression"&gt;
body
&lt;/when&gt;+
&lt;otherwise&gt;
body
&lt;/otherwise&gt;?
&lt;/choose&gt;
</source>
<p>Example:</p>
<source>
&lt;choose&gt;
&lt;when test="not(user/loggedIn)"&gt;
You're not logged in
&lt;/when&gt;
&lt;otherwise&gt;
You're already logged in
&lt;/otherwise&gt;
&lt;/choose&gt;
</source>
</s2>
<s2 title="value-of">
<p>The <code>value-of</code> tag evaluates an expression and outputs the result of the evaluation:</p>
<source>
&lt;value-of select="XPathExpression"/&gt;
</source>
<p>Example:</p>
<source>
&lt;value-of select="cart/numberOfItems"&gt;
</source>
</s2>
<s2 title="for-each">
<p>The <code>for-each</code> tag allows you to iterate over a collection of objects:</p>
<source>
&lt;for-each select="XPathExpression"&gt;
body
&lt;/for-each&gt;
</source>
<p>When using XPath expressions within <code>for-each</code> the current element is the
context node and can be referenced with XPath dot operator:</p>
<source>.</source>
<p>Example:</p>
<source>
&lt;for-each select="cart/cartItems[position() &lt;= $count]"&gt;
&lt;td&gt;&lt;value-of select="./productId"&gt;&lt;/td&gt;
&lt;/for-each&gt;
</source>
</s2>
<s2 title="continuation">
<p>The <code>continuation</code> tag returns the id of the current web continuation of your
Flowscript. You can refer to previous continuations by supplying the optional
<code>level</code> attribute. Zero is the current level, <code>-1</code> refers to the
previous continuation, and so on.</p>
<source>
&lt;continuation [level="Number"]/&gt;
</source>
<p>Example:</p>
<source>
&lt;xsp:attribute name="action"&gt;&lt;xsp:expr&gt;&lt;jpath:continuation/&gt;+".form"&lt;/xsp:expr&gt;&lt;/xsp:attribute&gt;
</source>
</s2>
</s1>
</body>
</document>