Function return processor
Core v2.2.0
The
processor is used inside
definitions to explicitly
return a value and immediately exit the function. If no
is used, the
function returns the result of its last expression.
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<function name="findProduct">
<def var="query"><call-param name="query"/></def>
<loop item="product" maxloops="100">
<xpath expression="//product">...</xpath>
<def var="name"><xpath expression=".//name/text()">${product}</xpath></def>
<if condition="${name == query}">
<return>${product}</return> <!-- Found! Exit function immediately -->
</if>
</loop>
<!-- Not found -->
<return>NOT_FOUND</return>
</function>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<function name="validateEmail">
<def var="email"><call-param name="email"/></def>
<if condition="${empty(email)}">
<return>false</return>
</if>
<regexp>
<regexp-pattern>^[\\w.-]+@[\\w.-]+\\.\\w+$</regexp-pattern>
<regexp-source>${email}</regexp-source>
</regexp>
<if condition="${!empty(group0)}">
<return>true</return>
</if>
<return>false</return>
</function>
</config>
definitions