References

An expression reads the data of the notice through references. A field reference gives the value of a field, a node reference points to a group of fields, and an attribute reference gives an attribute of a field. A reference is read from the context, unless it starts with a slash or follows a context override (::). A predicate after a reference keeps only the occurrences that meet a condition, and an index selects one occurrence (see Index). Properties, which you write after a colon, give other information about a field, such as its content exactly as written, or whether it is withheld from publication. This page also describes references to codelists and to variables.

Field reference

A field reference reads the value of a field from the notice.

Syntax
<field-identifier>
<field-identifier>[<condition>]
<field-identifier>[at <position>]
<field-identifier>

the identifier of a field defined in the SDK, for example BT-00-Number (see Identifiers).

<condition>

optional. A condition that keeps some of the occurrences of the field (see Predicate).

<position>

optional. The position of the one occurrence to select (see Index). Predicates and an index can follow each other.

A field reference is read from the context: EFX finds the occurrences of the field from there, and reads the value of each. A reference can also start from the root of the notice (see Absolute reference) or from the occurrence that a context variable holds (see Context override (::)).

The value has the EFX data type that corresponds to the type of the field (see Field types and their EFX data types). EFX converts the content of the field to that type: a number field gives a number, a date field gives a date, and so on. For a text, EFX removes the spaces at the start and end, and replaces each run of spaces, tabs or line breaks inside it with a single space. To read the content exactly as it is written in the notice, use the raw value.

Whether a field reference gives a single value (scalar) or a sequence depends on where you write it. It gives a sequence when the field can occur more than once from the context: because the field itself is repeatable, because it is a multilingual text, or because there is a repeatable node between the context and the field (see Repeatability). When the context is the field itself, a reference to that field gives the value of the current occurrence.

Where a single value is required, for example in a comparison with ==, a reference that gives a sequence is an error. In that case, you have three options:

  • use it with an operator or function that accepts a sequence, such as in or count;

  • select one value with an index, such as [at 1];

  • write it in a context from which the field gives a single value.

When the field is not in the notice, the reference gives no value: an empty sequence. In a presence condition (is present), the value of the field does not matter: the condition only tests whether the reference finds at least one occurrence of the field (see Presence).

Examples

BT-00-Number + 1

The value of a number field, used in a calculation.

WITH ND-Root COMPUTE count(BT-13-Text)

From ND-Root, BT-13-Text can occur more than once, because its node ND-RepeatableInSubNode is repeatable. The reference gives a sequence, and count counts its values.

WITH ND-RepeatableInSubNode COMPUTE BT-13-Text == 'a'

From one occurrence of ND-RepeatableInSubNode, the same field gives a single value, so you can compare it.

'a' in BT-00-Text-Multilingual

A multilingual field gives one value for each language, so you test it with in.

EFX-1 also accepted references with an XPath axis, such as preceding::BT-…, and references to a field of another notice, written notice(…)/BT-…. EFX-2 does not. In EFX-1 templates, a multilingual field was displayed in the preferred language automatically. In EFX-2, the reference gives the texts in all languages, and the template selects one, for example with :preferredLanguageText.

Node reference

A node reference points to the occurrences of a node, which groups related fields in the notice.

Syntax
<node-identifier>
<node-identifier>[<condition>]
<node-identifier>[at <position>]
<node-identifier>

the identifier of a node defined in the SDK, for example ND-SubNode.

<condition>

optional. A condition that keeps some of the occurrences of the node (see Predicate).

<position>

optional. The position of the one occurrence to select (see Index).

A node has no value of its own. You use a node reference where EFX needs a place in the notice, not a value:

Like a field reference, a node reference is read from the context, unless it starts with a slash (see Absolute reference).

Restrictions

  • You cannot use a node reference as a value: ND-SubNode == 'x' is an error. Apart from count, no built-in function accepts a node.

  • No property or attribute reference can follow a node reference.

Examples

ND-SubNode is present
WITH ND-Root COMPUTE ND-RepeatableNode[BT-00-Number-In-Repeatable-Node > 5] is present

True when at least one occurrence of ND-RepeatableNode has a number greater than 5.

WITH ND-RepeatableNode DISPLAY ${BT-00-Text-In-Repeatable-Node};

A template line whose context is a node. The line is displayed once for each occurrence of the node.

WITH ND-Root COMPUTE count(ND-RepeatableNode)

The number of occurrences of ND-RepeatableNode.

EFX-1 accepted only field and attribute references in presence conditions, and could not count nodes.

See also: Node

Attribute reference

An attribute reference reads an XML attribute of a field, such as the codelist name of a code or the language of a multilingual text.

Syntax
<field-reference>/@<attribute-name>
<field-reference>

a field reference. It can have predicates and an index, start with a slash, or follow a context override.

<attribute-name>

the name of the attribute as it is written in the notice, for example listName or languageID, directly after @, without a space.

EFX reads the attribute on each occurrence that the field reference gives. Its value is always a text. To calculate with it, convert it first, for example with number(…). The reference gives a single value or a sequence by the same rules as the field reference before it.

The SDK defines some attributes as fields of their own (see Attribute), and you can also read them with a field reference to that field. An attribute reference reads any attribute by its name, whether or not the SDK defines a field for it.

Restrictions

  • Only a field reference can come before /@: a node reference, a variable or any other expression cannot.

Examples

BT-00-Code/@listName == 'authority-activity'
'ENG' in BT-00-Text-Multilingual/@languageID

The language of each text of a multilingual field is an attribute, so there is one value for each language.

BT-00-Code[BT-00-Code == 'x']/@listName

Absolute reference

An absolute reference starts with a slash and is read from the root of the notice, whatever the context.

Syntax
/<field-identifier>
/<field-identifier>[<condition>]
/<node-identifier>
/<node-identifier>[<condition>]
<field-identifier>, <node-identifier>

the field or node to read.

<condition>

optional. A condition that keeps some of the occurrences (see Predicate).

A reference that starts with a slash gives the same result wherever you write it. Use it where the context is not the right starting point:

  • inside a predicate, where the context is the occurrence being tested;

  • in a template line or a rule-set whose context is deep in the notice;

  • to compare a value with all the values of a field in the notice.

An absolute field reference gives a single value or a sequence in the same way as the same reference from ND-Root: it gives a sequence when the field is repeatable, is a multilingual text, or is below a repeatable node.

An absolute reference cannot come after :: in a context override. A property, such as :rawValue, can follow it (see Raw value).

Examples

WITH ND-SubNode COMPUTE /BT-00-Text

The value of BT-00-Text, read from the root of the notice.

WITH ND-SubNode COMPUTE count(BT-13-Text[BT-13-Text == /BT-00-Text])

Inside the predicate, the context is the occurrence of BT-13-Text that is being tested, and /BT-00-Text is read from the root.

BT-00-Text is unique in /BT-00-Repeatable-Text
/ND-RepeatableNode[BT-00-Number-In-Repeatable-Node > 5] is present

Predicate

A predicate keeps, among the occurrences of a field or a node, only those that meet a condition.

Syntax
<field-reference>[<condition>]
<node-reference>[<condition>]
<field-reference>, <node-reference>

the field or node whose occurrences are filtered: a field reference or a node reference. It can start with a slash, follow a context override, have a linked property, and already have predicates or an index.

<condition>

an expression of type indicator.

EFX checks the condition once for each occurrence of the field or node. It keeps the occurrences for which the condition is true, and leaves out the others.

Inside the brackets, the context is the occurrence that is being tested, and the references in the condition are read from it. In BT-13-Text[BT-13-Number > 0], for example, the number is read in the same occurrence of ND-RepeatableInSubNode as the text that is being tested. A reference to the filtered field itself gives the value of the occurrence being tested. To read data from somewhere else, use an absolute reference, a variable, or a context override with a context variable.

A predicate does not change whether a reference gives a single value or a sequence: it only removes occurrences. A reference to a repeatable field with a predicate is still a sequence. To select one occurrence, use an index.

Several predicates can follow each other: BT-13-Text[BT-13-Number > 0][BT-13-Indicator == TRUE] keeps the occurrences that meet both conditions, as and would. A predicate after an index tests the occurrence that the index selects.

You can write a predicate wherever a field or node reference is accepted, including the context of a template line or a rule-set, a context variable, and the reference after :: in a context override. The only exception is the context of a single expression.

Restrictions

  • The condition must be of type indicator. A number in the brackets is not a position: BT-13-Text[1] is an error. To select by position, write an index: BT-13-Text[at 1].

  • A predicate can only follow a field or node reference. It cannot follow a variable, a sequence in square brackets, an iteration or a function call: ['a', 'b'][TRUE] is an error. To filter such a sequence, use an iteration.

  • Inside the condition, a field that can have several values from the occurrence that is being tested is a sequence, as anywhere else, and you cannot compare it with ==. Use a quantified expression instead (see the last example).

Examples

WITH ND-Root COMPUTE count(BT-13-Text[BT-13-Number > 0])

The number of BT-13-Text values whose BT-13-Number, in the same node, is positive.

WITH ND-Root COMPUTE ND-RepeatableNode[BT-00-Text-In-Repeatable-Node == 'x'] is present
WITH ND-Root COMPUTE count(BT-00-Repeatable-Text[BT-00-Repeatable-Text like '[A-Z]+'])

In the predicate, BT-00-Repeatable-Text is the value of the occurrence that is being tested.

WITH ND-Root COMPUTE count(BT-13-Text[BT-13-Number > 0][BT-13-Indicator == TRUE])

Two predicates: the texts whose number is positive and whose indicator is true.

WITH ND-Root COMPUTE BT-00-Text[some text:$x in BT-00-Repeatable-Text satisfies $x == 'test']

BT-00-Repeatable-Text can have several values, so you test it with some … satisfies, not with ==.

EFX-1 accepted at most one predicate after a reference.

See also: Context changes

Context override (::)

A context override reads a field or a node from the occurrence that a context variable holds, instead of from the context.

Syntax
$<variable-name>::<field-reference>
$<variable-name>::<node-reference>
<variable-name>

the name of a context variable.

<field-reference>, <node-reference>

the field or node to read from there: an identifier, which can be followed by predicates and an index, and for a field by a linked property.

The field or node after :: is read from the occurrence that the variable holds, as if that occurrence were the context. The result is a single value when the field gives a single value from that occurrence: BT-21-Number gives a single value from an occurrence of ND-RepeatableNode, so $n::BT-21-Number is a single value when $n holds one occurrence of that node.

You need a context override wherever the context is not the occurrence that you want to read from:

  • An iteration does not change the context. When an iteration takes the occurrences of a node with a context variable, you read a field of the current occurrence with $variable::field. Without the override, the field would be read from the context of the whole expression.

  • In a nested template line, a context variable declared in a line above names the context of that line, and $variable::field reads a field from there.

  • Inside a predicate, where the context is the occurrence that is being tested, $variable::field reads a field from the occurrence that the variable holds.

To read a field from some occurrences of a node only, iterate over those occurrences with a context variable, as in the third example.

The override is part of the path to the field: when the variable holds no occurrence, the reference gives no value.

You can use the result wherever a field or node reference is accepted: in presence conditions, before /@ in an attribute reference, before :rawValue, and with a predicate or an index.

Restrictions

  • Only a context variable can come before ::. A field, a node or a variable of another type is an error: ND-RepeatableNode::BT-21-Number is an error.

  • Another :: cannot follow a context override.

  • The reference after :: cannot start with a slash.

  • A privacy property cannot follow a context override (see Privacy property).

Examples

WITH ND-Root COMPUTE for context:$n in ND-RepeatableNode return $n::BT-00-Text-In-Repeatable-Node

One value for each occurrence of ND-RepeatableNode, read in that occurrence.

WITH ND-Root COMPUTE every context:$n in ND-RepeatableNode satisfies $n::BT-21-Number > 0

From one occurrence of ND-RepeatableNode, BT-21-Number is a single value, so you can compare it.

WITH ND-Root COMPUTE sum(for context:$n in ND-RepeatableNode[BT-00-Text-In-Repeatable-Node == 'x'] return $n::BT-00-Number-In-Repeatable-Node)

The numbers of the occurrences of ND-RepeatableNode whose text is x.

WITH ND-Root COMPUTE every context:$n in ND-RepeatableNode satisfies count(BT-23-Number[BT-23-Number > $n::BT-21-Number]) >= 0

Inside the predicate, $n::BT-21-Number is read from the occurrence of ND-RepeatableNode that $n holds.

WITH context:$lot = ND-RepeatableNode DISPLAY ${BT-00-Text-In-Repeatable-Node};
    WITH ND-RepeatableInRepeatableNode DISPLAY ${BT-23-Text} (${$lot::BT-00-Number-In-Repeatable-Node});

In the nested template line, the context is ND-RepeatableInRepeatableNode, and the number is read from the occurrence of ND-RepeatableNode that $lot holds.

In EFX-1, a field or a node could also come before ::. EFX-2 accepts only a context variable there, so that it is always clear which occurrence the reference is read from. A node can now follow ::.

Field property

A field property gives information about a field other than its value: its content exactly as written, the privacy fields that accompany it, whether it is withheld from publication, or its text in the preferred language.

Syntax
<field>:<property>
<field>

the field whose property you read. What you can write here depends on the property (see below).

<property>

the name of the property, written exactly as in the table, with the same upper and lower case.

Property Gives Type Entry

rawValue

the content of the field exactly as written in the notice

text

Raw value

publicationDate

the date from which a withheld field can be published

date

Linked field property

justificationCode

the code of the justification for withholding the field

text

Linked field property

justificationDescription

the description of the justification for withholding the field

text

Linked field property

privacyCode

the privacy code of the field

text

Privacy property

isWithholdable

whether the field can be withheld from publication

indicator

Privacy property

wasWithheld

whether the field was withheld from publication

indicator

Privacy property

isWithheld

whether the field is still withheld

indicator

Privacy property

isDisclosed

whether the field was withheld and its value has since been disclosed

indicator

Privacy property

isMasked

whether the value of the field has been replaced by a masking value

indicator

Privacy property

preferredLanguage

the language of the preferred text of a multilingual field (templates only)

text

Preferred language property

preferredLanguageText

the preferred text of a multilingual field (templates only)

text

Preferred language property

The linked properties publicationDate, justificationCode and justificationDescription follow a field identifier and then work like field references. The privacy properties follow a field identifier only. rawValue, preferredLanguage and preferredLanguageText follow any field reference: it can start with a slash, have predicates and an index, and follow a context override. You can put spaces around the colon.

Field properties are new in EFX-2.

Linked field property

A linked field property reads one of the privacy fields that accompany a field that can be withheld from publication.

Syntax
<field-identifier>:publicationDate
<field-identifier>:justificationCode
<field-identifier>:justificationDescription
<field-identifier>:<linked-property>[<condition>]
<field-identifier>

a field that can be withheld from publication.

<linked-property>

one of publicationDate, justificationCode, justificationDescription.

<condition>

optional. See Predicate.

In eForms, the publication of some information in a notice can be postponed: the field is withheld from publication. For each field that can be withheld, the SDK defines a privacy code and four companion fields, which record in the notice that the field is withheld, why, and until when. The linked properties read three of these companion fields without naming them:

publicationDate

the date from which the field can be published. Type date.

justificationCode

the code of the justification for withholding the field. Type text.

justificationDescription

the description of the justification. It is a multilingual text, so it gives one value for each language.

A linked property works like a field reference to the companion field. EFX reads it from the context, and the same rules decide whether it gives a single value or a sequence. You can use it wherever you can use a field reference: with predicates and an index, after a slash, after a context override, before /@, :rawValue or :preferredLanguageText, and in presence conditions.

Restrictions

  • The field must be one that can be withheld from publication.

Examples

WITH ND-RepeatableNode COMPUTE BT-00-Text-In-Repeatable-Node:publicationDate > 2025-01-01Z
WITH ND-RepeatableNode COMPUTE BT-00-Text-In-Repeatable-Node:justificationCode is present
WITH ND-RepeatableNode DISPLAY ${BT-00-Text-In-Repeatable-Node:justificationDescription:preferredLanguageText};

In a template, the justification in the preferred language.

In EFX-1, you could refer to the companion fields only by their own identifiers.

See also: Privacy property

Privacy property

A privacy property says whether a field can be withheld from publication and, if so, whether it was withheld, is still withheld, or has been disclosed.

Syntax
<field-identifier>:privacyCode
<field-identifier>:isWithholdable
<field-identifier>:wasWithheld
<field-identifier>:isWithheld
<field-identifier>:isDisclosed
<field-identifier>:isMasked
<field-identifier>

the field. The privacy property follows the field identifier directly.

The properties mean the following (the companion fields are described in Linked field property):

privacyCode

the privacy code that the SDK gives to the field. A notice names its withheld fields by this code. Type text. The value comes from the SDK and does not depend on the content of the notice.

isWithholdable

TRUE when the field can be withheld from publication, that is, when the SDK gives it a privacy code; FALSE otherwise. The value comes from the SDK and does not depend on the content of the notice.

wasWithheld

TRUE when the notice states that the field is withheld from publication, that is, when the privacy code of the field is among its withheld fields. It remains TRUE after the publication date has passed.

isWithheld

TRUE when the field was withheld and is still withheld: either no publication date is given, or the publication date is later than the current date.

isDisclosed

TRUE when the field was withheld, is no longer withheld because its publication date has been reached, and its value is not the masking value.

isMasked

TRUE when the field was withheld and its value is the masking value. The masking value takes the place of the real value of a withheld field; the SDK defines one for each data type, for example unpublished for texts and codes, -1 for numbers and 1970-01-01Z for dates.

All the privacy properties except privacyCode are indicators, which you can combine with logical operators.

wasWithheld, isWithheld, isDisclosed and isMasked read the privacy information of the notice from the context. To get the status of each occurrence of a repeatable field, use them in the context of the field or of its node, for example in a template line or a rule-set whose context is the field.

A privacy property can also follow a linked property, as in BT-00-Text-In-Repeatable-Node:publicationDate:isWithholdable. It then applies to the companion field, which cannot itself be withheld.

Restrictions

  • Except for isWithholdable, the field must be one that can be withheld from publication.

  • The field identifier cannot have a predicate or an index, start with a slash or follow a context override.

Examples

WITH ND-RepeatableNode COMPUTE BT-00-Text-In-Repeatable-Node:isWithheld
WITH ND-RepeatableNode COMPUTE BT-00-Date-In-Repeatable-Node:wasWithheld and not(BT-00-Date-In-Repeatable-Node:isWithheld)

True when the date was withheld and its publication date has been reached.

---- STAGE 1a ----
WITH ND-RepeatableNode
  ASSERT BT-00-Number-In-Repeatable-Node:isWithheld or not(BT-00-Number-In-Repeatable-Node:isMasked)
  AS ERROR R-AB1-C2D FOR BT-00-Number-In-Repeatable-Node IN *;

A rule that allows a masking value only while the field is withheld.

From the SDK (view-templates/1.efx, indentation removed)
WITH BT-16-Organization-Company WHEN BT-16-Organization-Company:isMasked DISPLAY #{name}: #{auxiliary|text|undisclosed} OTHERWISE DISPLAY #{name}: $value; // Organization Part Name

The line displays a label instead of a masked value.

Privacy properties are new in EFX-2.

See also: Field property

Preferred language property

The preferred language properties select one of the texts of a multilingual field, for display in a template.

Syntax
<field-reference>:preferredLanguage
<field-reference>:preferredLanguageText
<field-reference>

a reference to a multilingual text field. It can start with a slash, have predicates and an index, and follow a context override.

preferredLanguage

the language code of the preferred text, for example ENG. Type text.

preferredLanguageText

the preferred text itself. Type text.

A multilingual field holds the same text in several languages, and a template usually displays only one of them. These properties choose the text in the preferred language. They do the same as the functions preferred-language and preferred-language-text, whose entries describe how the preferred language is chosen.

Restrictions

  • You can use these properties in template files only, not in single expressions or rules files.

  • The field must be a multilingual text field.

Examples

WITH ND-Root DISPLAY ${BT-00-Text-Multilingual:preferredLanguageText};
WITH ND-RepeatableInSubNode DISPLAY ${BT-13-TextMultilingual:preferredLanguageText} (${BT-13-TextMultilingual:preferredLanguage});
EFX-1 templates displayed multilingual fields in the preferred language automatically. In EFX-2, the template chooses: these properties or functions select the preferred text, and the field reference alone gives all the texts.

See also: Field property

Raw value

The raw value of a field is its content exactly as written in the notice, as a text.

Syntax
<field-reference>:rawValue
<field-reference>

a reference to a field. It can start with a slash, have predicates and an index, and follow a context override.

A field reference converts the content of the field to the data type of the field and, for a text, removes the extra spaces (see Field reference). The raw value skips this conversion: it is always a text, and it is the content as written, spaces included. For a number field, it is the number as written, for example 12.50. For a duration field, it is the number written in the notice, without its unit. To calculate with a raw value, convert it first, for example with number(…).

Use the raw value to check how a value is written, to compare identifiers exactly as they are written in the notice, or to apply a text function to a field of another type.

A raw value gives a single value or a sequence by the same rules as a field reference. For a multilingual field, it gives one value for each language.

Restrictions

  • :rawValue can only follow a field reference. It cannot follow an attribute reference, a variable or any other expression: BT-00-Text/@Attribute:rawValue is an error.

Examples

BT-00-Number:rawValue like '[0-9]+\.[0-9]+'

True when the number is written with a decimal point.

string-length(BT-00-Text:rawValue)
number(BT-00-Duration:rawValue) > 3
From the SDK (validation/stage-5m.efx)
LET text* : $global-lot-ids = BT-137-Lot:rawValue;

The identifiers of all the lots, as written, held in a sequence variable.

The raw value is new in EFX-2.

See also: Field property

Codelist reference

A codelist reference gives all the codes of a codelist, as a sequence of texts.

Syntax
[...<codelist-identifier>]
<codelist-identifier>

the identifier of a codelist defined in the SDK, for example main-activity, directly after ..., without a space.

The codes come from the SDK when the expression is translated, so the sequence does not depend on the content of the notice. You mostly use a codelist reference with in and not in, to check that a code belongs to a codelist, but you can use it wherever a sequence of texts is expected.

Although you write [...<codelist-identifier>] in square brackets, it is not a sequence literal: you cannot write anything else in the brackets. To combine a codelist with other values, use a function such as value-union.

Examples

BT-00-Code in [...main-activity]
BT-00-Code not in [...main-activity]
value-union([...main-activity], ['other'])
LET text*:$activities = [...main-activity];
WITH ND-Root DISPLAY ${count($activities)};

A codelist held in a sequence variable of a template file.

From the SDK (validation/rules.efx)
  ASSERT BT-01-notice in [...legal-basis-1]
    AS ERROR R-D9C-MQY
    FOR BT-01-notice
    IN 1;

A rule that checks a code against a codelist.

In EFX-1, a codelist was written in parentheses: (main-activity). EFX-2 writes [...main-activity], so that parentheses only group expressions.

See also: Membership, Codelist

Variable reference

A variable reference reads the value of a variable or of a parameter.

Syntax
$<variable-name>
<variable-name>

the name of a variable, iterator variable, context variable or parameter, directly after $, without a space. Names are case-sensitive.

The name must be declared, and the reference must be within its scope (see Scope of variables). You declare variables with LET or in a WITH clause, in an iteration, or as parameters of a single expression, of a user-defined function or of a callable template.

The reference has the type of the variable. A variable declared with a sequence type, such as text*, is a sequence, and you cannot use it where a single value is required.

A reference does not compute the value of the variable again: it reads the value computed where the variable is declared (see Variable declaration).

A reference to a context variable has two uses. Followed by ::, it is the starting point of a context override. Used alone, a context variable that holds a field gives the value of that occurrence of the field, with the data type of the field. A context variable that holds a node has no value.

An index can follow a variable, as in $names[at 1], but a predicate cannot. In template files, the name of a dictionary followed by a key in square brackets is a dictionary lookup.

Examples

LET number:$threshold = 100;
WITH ND-Root DISPLAY ${BT-00-Number > $threshold};
WITH ND-Root COMPUTE for text:$x in BT-13-Text return upper-case($x)
LET text*:$allowed = ['a', 'b'];
WITH ND-Root DISPLAY ${BT-00-Text in $allowed};
WITH context:$n = BT-13-Number DISPLAY ${$n + 1};

A context variable that holds a number field, used as a number.

EFX-1 had only iterator variables and parameters, and their names could not contain hyphens.

See also: Context variable