home *** CD-ROM | disk | FTP | other *** search
- <?xml version='1.0' encoding='ISO-8859-1'?>
- <!--
- Copyright 1999-2004 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "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>
- <if test="XPathExpression">
- body
- </if>
- </source>
- <p>Example:</p>
- <source>
- <jpath:if test="cart/numberOfItems = 0">
- Your cart is empty
- </jpath:if>
- </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>
- <choose>
- <when test="XPathExpression">
- body
- </when>+
- <otherwise>
- body
- </otherwise>?
- </choose>
- </source>
- <p>Example:</p>
- <source>
- <choose>
- <when test="not(user/loggedIn)">
- You're not logged in
- </when>
- <otherwise>
- You're already logged in
- </otherwise>
- </choose>
- </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>
- <value-of select="XPathExpression"/>
- </source>
- <p>Example:</p>
- <source>
- <value-of select="cart/numberOfItems">
- </source>
- </s2>
- <s2 title="for-each">
- <p>The <code>for-each</code> tag allows you to iterate over a collection of objects:</p>
- <source>
- <for-each select="XPathExpression">
- body
- </for-each>
- </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>
- <for-each select="cart/cartItems[position() <= $count]">
- <td><value-of select="./productId"></td>
- </for-each>
- </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>
- <continuation [level="Number"]/>
- </source>
- <p>Example:</p>
- <source>
- <xsp:attribute name="action"><xsp:expr><jpath:continuation/>+".form"</xsp:expr></xsp:attribute>
- </source>
- </s2>
- </s1>
- </body>
- </document>
-