Expression forms
An EFX expression that you use on its own, outside a template file or a rules file, must say from which place in the notice it is read. So you write it in one of two forms: a single expression, which computes a value, or a selector, which points to data in the notice. Both can also declare parameters, whose values the application gives when it uses the expression. In template files and rules files, you write expressions without these forms, because the template line or the rule-set already gives the context.
Single expression
A single expression is an EFX expression that stands on its own: it names its context and computes a value from the notice.
WITH <context> COMPUTE <expression> WITH <context>, <parameter-declaration>, … COMPUTE <expression>
- <context>
-
the identifier of a field or a node. The expression is read from an occurrence of it (see Evaluation context).
- <parameter-declaration>
-
optional. One or more parameters, separated by commas (see Parameters of a single expression).
- <expression>
-
any EFX expression. Its value is the result of the single expression.
You use a single expression where an EFX expression is stored or exchanged on its own. The field metadata of the SDK, for example, uses single expressions for the conditions under which a field is mandatory or forbidden. The application that uses a single expression chooses the occurrence of the context from which it is read.
The result can have any data type, and can be a single value (scalar) or a sequence. For example,
WITH ND-Root COMPUTE BT-13-Text gives all the values of BT-13-Text, a sequence of texts.
You can write a single expression on several lines, with comments. You can end it with a semicolon, but you do not have to.
Restrictions
-
The context is only the identifier of a field or a node: it cannot have a predicate (
WITH ND-RepeatableNode[…]), start with a slash (WITH /ND-Root) or declare a context variable.
Examples
WITH ND-Root COMPUTE BT-00-Number + 1
WITH BT-13-Text COMPUTE BT-13-Number > 10
The context is a field. From there, BT-13-Number, which is in the same node, is a single value.
WITH ND-RepeatableNode
COMPUTE BT-21-Number > 0
and count(BT-23-Number) > 2
A single expression on several lines.
fields/fields.json)WITH ND-LocalLegalBasisWithID COMPUTE BT-01(c)-Procedure is not present
The condition under which the field BT-01(d)-Procedure is forbidden.
EFX-1 wrote a single expression with braces: {ND-Root} ${BT-00-Number + 1}. EFX-2 writes WITH … COMPUTE
instead, in the same way as the rest of the language. EFX-2 does not accept the form with braces.
|
See also: Selector, Expression block
Selector
A selector points to data in the notice: it gives the occurrences of a field, a node or an attribute, that is, where they are, not their values.
WITH <context> SELECT <selection> WITH <context>, <parameter-declaration>, … SELECT <selection>
- <context>
-
the identifier of a field or a node, as in a single expression.
- <parameter-declaration>
-
optional. One or more parameters, separated by commas.
- <selection>
-
a field reference, a node reference or an attribute reference. It can start with a slash, and predicates and indexes can follow it, in any order. A field reference can also end with a linked field property, such as
:publicationDate(see Linked field property).
Selectors exist because an application that uses EFX with a tool that works directly on the XML document sometimes needs to know where the data is, not what it contains. For example, a selector can tell an XML processor which XML elements to select.
As with a single expression, you can end the WITH … SELECT form with a semicolon.
A selector is read like the same reference in an expression: from the context, or from the root of the notice when it
starts with a slash. It gives every occurrence that the reference matches, so it does not matter here whether the
field or node is repeatable. An index selects one of these occurrences: WITH ND-Root SELECT ND-RepeatableNode[at 2]
gives the second occurrence of the node (see Index).
Restrictions
-
You use a selector only on its own. It cannot appear inside an expression, and an expression cannot take the place of the selection:
WITH ND-Root SELECT BT-00-Text == 'x'andWITH ND-Root SELECT count(BT-13-Text)are errors. -
The selection cannot be a literal, a variable, a context override (
$n::BT-21-Number) or a raw value (BT-00-Number:rawValue).
Examples
WITH ND-Root SELECT BT-00-Text
WITH ND-Root SELECT ND-RepeatableNode[BT-21-Number > 5]
The occurrences of the node that meet the condition.
WITH ND-SubNode SELECT /BT-00-Text
Read from the root of the notice, whatever the context.
WITH ND-Root SELECT BT-00-Text/@Attribute
An attribute.
WITH ND-Root SELECT ND-RepeatableNode[at 2]
The second occurrence of the node.
EFX-1 has selectors from SDK 1.16 onwards, written with braces: {ND-Root} &{BT-13-Text}. EFX-2 writes
WITH … SELECT instead, and does not accept the form with braces.
|
See also: Field reference, Node reference, Attribute reference
Parameters of a single expression
A parameter is a named value that a single expression or a selector receives from the application that uses it.
<type>:$<name> <type>*:$<name>
- <type>
-
the data type of the parameter:
text,number,indicator,date,timeorduration. With a star, the parameter is a sequence of values of that type. - <name>
-
the name of the parameter (see Identifiers).
With parameters, you can use the same expression with different values. You declare them after the context, separated
by commas, and use them in the expression by their name, such as $threshold.
The application gives one value for each parameter, in the order of the declarations. A value is a literal of the declared type or, for a sequence parameter, literals in square brackets:
<literal> [<literal>, <literal>, …]
- <literal>
-
a text, number, indicator, date, time or duration literal (see Literals).
A parameter value is a literal, not an expression: a field reference or a calculation such as 50 + 50 is an error,
and so is a text without quotes. You write it on its own, without braces: 100, not {100}.
User-defined functions, callable templates and dynamic functions declare their parameters in the same way (see User-defined function declaration, Template section and Dynamic function declaration).
Restrictions
-
Every parameter must receive a value of its type.
-
A sequence value contains at least one literal, and all its literals have the same type:
[]and['works', 1]are errors. -
contextis not a parameter type.
Examples
WITH ND-Root, number:$threshold COMPUTE BT-00-Number > $threshold
With the value 100 for $threshold, the expression tests whether BT-00-Number is greater than 100.
WITH ND-Root, date:$from, date:$to COMPUTE BT-00-StartDate >= $from and BT-00-StartDate <= $to
Two parameters, with for example the values 2025-01-01Z and 2025-12-31Z, in that order.
WITH ND-Root, text*:$codes COMPUTE BT-00-Code in $codes
A sequence parameter, with for example the value ['works', 'services'].
WITH ND-Root, text:$code SELECT BT-00-Text[BT-00-Code == $code]
A selector with a parameter, with for example the value 'works'.
EFX-1 wrote a parameter value in braces, {100}. It called the type duration measure, and had no sequence
parameters.
|
See also: Sequence literal, Variable reference