Validation stages
A rules file groups its rules in validation stages. A validation stage starts with a stage header, which gives the stage its identifier, and contains rule-sets. Stage variables, declared at the start of a stage, hold values that all the rules of that stage can use.
Validation stage
A validation stage is a named group of rule-sets that the validation evaluates together. Validation stages put the rules in a logical order. For example, the rules that check whether fields are present or forbidden come before the rules that check the values of those fields.
---- STAGE <stage-identifier> ---- <stage-variable> … <rule-set> …
- <stage-identifier>
-
the identifier of the stage, for example
1a,2bor4. It is made of letters, digits, hyphens (-) and underscores (_). It starts with a letter or a digit and does not end with a hyphen. - <stage-variable>
-
optional. Stage variables (see Stage variable).
- <rule-set>
-
one or more rule-sets (see Rule-set).
The first line is the stage header. It is made of at least three hyphens, the keyword STAGE, the stage
identifier, and again at least three hyphens. Spaces between the hyphens and the keyword are optional, and at least
one space separates the keyword from the identifier. A comment can follow the header on the same line. You write the
keyword STAGE in upper case. The SDK writes stage headers with three hyphens on each side, for example
--- STAGE 1a ---.
A validation stage contains everything that follows its header, up to the next stage header or the end of the rules file. Its stage variables come first, followed by its rule-sets.
The validation evaluates each validation stage as a unit: it checks all the rules of the stage against the notice
together. It evaluates the validation stages one after the other, in the order in which they appear in the rules file
once the include directives are replaced. This order does not depend on the stage identifiers: a stage 2 written
before a stage 1 comes first.
Restrictions
-
Two validation stages of the same rules file, including the stages inserted by include directives, cannot have the same identifier.
-
A validation stage must contain at least one rule-set.
Examples
---- STAGE 1a ----
WITH ND-Root
ASSERT BT-00-Text is present
AS ERROR R-K7P-M2Q
FOR BT-00-Text
IN *;
---- STAGE 2a ----
WITH ND-Root
ASSERT string-length(BT-00-Text) <= 200
AS ERROR R-X3F-N8W
FOR BT-00-Text
IN *
Two validation stages. Stage 1a checks that a field is present, and stage 2a checks its value.
--- STAGE 1a ---
WITH ND-Root ASSERT BT-00-Text is present AS ERROR R-K7P-M2Q FOR BT-00-Text IN *;
---------- STAGE 2b ----------
WITH ND-Root ASSERT BT-00-Text is present AS ERROR R-X3F-N8W FOR BT-00-Text IN *
---STAGE 4---
WITH ND-Root ASSERT BT-00-Text is present AS ERROR R-H9T-V5L FOR BT-00-Text IN *
Different ways of writing a stage header. The number of hyphens and the spaces around the keyword do not matter.
| EFX-1 had no validation stages. The Schematron files of SDK 1 already grouped the rules by validation stage, but EFX did not show this grouping. |
See also: Rules file, Stage variable, Rule-set, Identifiers
Stage variable
A stage variable is a variable declared at the start of a validation stage. All the rules of that stage can use it.
LET <type>:$<variable-name> = <expression>; LET dynamic:$<variable-name> = ?<function-name>(<arguments>);
- <type>
-
the data type of the variable:
text,number,indicator,date,timeorduration, followed by*for a sequence (see Variable declaration). - <variable-name>
-
the name of the variable (see Identifiers).
- <expression>
-
an expression of the declared type, which gives the value of the variable.
- <function-name>, <arguments>
-
a call to a dynamic function, for a dynamic variable (see Dynamic variable).
You declare a stage variable in the same way as a global variable, but after the header of a validation stage and before its first rule-set. EFX computes it once for each notice. Its expression has no context: EFX reads the field and node references in it from the root of the notice. So a reference to a field that can occur more than once gives the values of all its occurrences in the notice.
You can use a stage variable in the stage variables that follow it, and in all the rule-sets of its stage. It can use global variables. It is not visible in other validation stages, so two stages can declare stage variables with the same name.
Restrictions
-
You can declare stage variables only between the stage header and the first rule-set of the stage, not between rule-sets.
-
The name of a stage variable cannot be the name of a global variable, of another variable of the same stage, or of a variable declared in a
WITHclause of the same stage.
Examples
---- STAGE 5 ----
LET text*:$all-texts = BT-00-Text-In-Repeatable-Node;
WITH ND-RepeatableNode
ASSERT BT-00-Text-In-Repeatable-Node is unique in $all-texts
AS ERROR R-H9T-V5L
FOR BT-00-Text-In-Repeatable-Node
IN *;
The stage variable holds the values of the field in all the repeatable nodes of the notice. The rule checks that the value in each repeatable node occurs only once.
LET number:$max-number = 1000;
---- STAGE 2a ----
LET number:$min-number = $max-number / 100;
LET number:$sub-count = count(BT-13-Text);
WITH ND-Root
ASSERT BT-00-Number >= $min-number
AS WARNING R-B6J-C4R
FOR BT-00-Number
IN *
WITH ND-SubNode
ASSERT $sub-count <= 20
AS ERROR R-Y2N-G7S
FOR BT-13-Text
IN *
Two stage variables used by two rule-sets of the stage. EFX computes the first stage variable from a global variable.
validation/stage-5m.efx)--- STAGE 5m ---
LET text* : $global-lot-ids = BT-137-Lot:rawValue;
LET text* : $global-org-ids = OPT-200-Organization-Company:rawValue;
The start of a validation stage. Its stage variables collect identifiers from the whole notice, and the rules of the stage then check that each identifier occurs only once.
| Stage variables are new in EFX-2. |
See also: Global variable,
WITH clause,
Variable declaration,
Scope of variables