Rule-sets
Inside a validation stage, rule-sets group the rules. The validation evaluates all the rules of a rule-set in the
same context, which the WITH clause at the start of the rule-set sets. The WITH clause can also declare variables
that the rules of the rule-set share.
Rule-set
A rule-set is a group of rules that the validation evaluates in the same context. It starts with a WITH clause,
followed by one or more rules.
<with-clause> <rule> … <with-clause> <conditional-rule> … <fallback-rule>
- <with-clause>
-
the context of the rule-set and, optionally, variables for its rules (see
WITHclause). - <rule>
-
one or more rules, with or without a
WHENclause (see Rule). - <conditional-rule>
-
one or more rules that each have a
WHENclause (seeWHENclause). - <fallback-rule>
-
a rule introduced by
OTHERWISE(seeOTHERWISEclause).
The validation evaluates the rules of a rule-set once for each occurrence that the context matches in the notice, for example once for each occurrence of a repeatable node. The rules do not depend on each other. Each rule has its own condition, severity, identifier, target and notice subtypes, and several rules can produce findings for the same occurrence.
A rule-set takes one of two forms. In the first form, the rules can be any mix of rules with and without a WHEN
clause. The second form gives a fallback rule: every rule has a WHEN clause, except the last one. The last one
starts with OTHERWISE, and applies when none of the WHEN conditions is true.
A rule-set ends where the next rule-set, the next validation stage or an include directive starts, or at the end of
the rules file. Each rule ends with its own semicolon, so the rule-set itself has no end mark. You can use line breaks
and indentation freely. The SDK writes each clause of a rule on a line of its own, and indents the rules under the
WITH clause.
Restrictions
-
A rule-set contains at least one rule.
-
A rule that starts with
OTHERWISEis allowed only in a rule-set in which every other rule has aWHENclause. It must be the last rule, and a rule-set can contain only one. -
A semicolon on its own after the last rule of a rule-set is an error: the semicolon of the last rule already ends it.
Examples
WITH ND-RepeatableNode
ASSERT BT-00-Text-In-Repeatable-Node is present
AS ERROR R-K7P-M2Q
FOR BT-00-Text-In-Repeatable-Node
IN *;
ASSERT BT-00-Date-In-Repeatable-Node is present
AS WARNING R-X3F-N8W
FOR BT-00-Date-In-Repeatable-Node
IN 1-5;
A rule-set with two rules, which the validation checks for each occurrence of the repeatable node. Each rule ends with a semicolon.
WITH ND-Root
ASSERT BT-00-Text is present
AS ERROR R-H9T-V5L
FOR BT-00-Text
IN *;
WHEN BT-00-Indicator == TRUE
ASSERT BT-00-Number is present
AS ERROR R-B6J-C4R
FOR BT-00-Number
IN *;
REPORT BT-00-Number > 1000000
AS WARNING R-Y2N-G7S
FOR BT-00-Number
IN *;
A rule-set that mixes rules with and without a WHEN clause.
WITH ND-Root
WHEN BT-00-Code == 'code1'
ASSERT BT-00-Number > 0
AS ERROR R-D4K-P9M
FOR BT-00-Number
IN *;
WHEN BT-00-Code == 'code2'
ASSERT BT-00-Number == 0
AS ERROR R-F5V-T6B
FOR BT-00-Number
IN *;
OTHERWISE ASSERT BT-00-Number is not present
AS ERROR R-W1D-J2Y
FOR BT-00-Number
IN *;
A rule-set with two conditional rules and a fallback rule, which applies when the code is neither code1 nor
code2.
validation/stage-1a.efx)--- STAGE 1a ---
WITH ND-Root
ASSERT OPP-070-notice is present
AS ERROR R-TMP-001
FOR OPP-070-notice
IN *;
ASSERT ND-Lot is not present
AS ERROR R-TMP-002
FOR ND-Lot
IN 1-6,E2,X01,X02;
ASSERT ND-Lot is present
AS ERROR R-TMP-003
FOR ND-Lot
IN 7-40,E3-E6,T01,T02;
ASSERT ND-Part is not present
AS ERROR R-TMP-004
FOR ND-Part
IN 7-40,E3-E6,T01,T02,X01,X02;
ASSERT ND-Part is present
AS ERROR R-TMP-005
FOR ND-Part
IN 4-6,E2;
A validation stage with one rule-set. Its rules check which nodes must be present or absent, depending on the notice subtype.
| EFX-1 had no rule-sets. In the Schematron files of SDK 1, the rules were grouped by context in a similar way. |
See also: Validation stage
WITH clause
The WITH clause sets the context of a rule-set and can declare variables for the rules of the rule-set.
WITH <context> WITH <variable>, …, <context> WITH <context>, <variable>, … WITH <variable>, …, <context>, <variable>, … WITH EVERY <context> WITH EVERY <variable>, …, <context>, <variable>, …
- <context>
-
the context of the rule-set. It is one of the following:
-
a field reference or a node reference, which can be absolute and can have predicates and an index (see Field reference, Node reference, Predicate and Index);
-
a context variable,
context:$<variable-name> = <reference>, where<reference>is a field reference or a node reference (see Context variable).
-
- <variable>
-
optional. A variable written without
LETand without a semicolon at the end:<type>:$<variable-name> = <expression>(see Variable declaration), ordynamic:$<variable-name> = ?<function-name>(<arguments>)(see Dynamic variable). Commas separate the variables from each other and from the context. EVERY-
optional. Applies the rules to every XML element of the kind of the context (see below).
The context sets the occurrences for which the validation evaluates the rules of the rule-set. A node context matches every occurrence of the node in the notice, and a field context every occurrence of the field. A predicate limits the context to the occurrences for which the predicate is true. In the rules, EFX reads field and node references from the occurrence under evaluation (see Evaluation context).
A rule-set has no context around it. So, in a WITH clause, a relative and an absolute reference point to the same
occurrences: WITH ND-SubNode and WITH /ND-SubNode mean the same. You write the root of the notice as ND-Root.
A context variable gives a name to the occurrence under evaluation, so that the rules can refer to it by that name. You need this, for example, inside a predicate, where the context changes (see Context override). A context variable always refers to one occurrence at a time, even when the context is a field that can occur more than once.
The place of a variable before or after the context decides how EFX evaluates it:
-
EFX computes a variable declared before the context once for each notice, whatever the context. It reads the field and node references in it from the root of the notice, as in a global variable. So a reference to a field that can occur more than once gives the values of all its occurrences in the notice.
-
EFX computes a variable declared after the context for each occurrence that the context matches. It reads the field and node references in it from that occurrence.
A variable can use the variables declared before it in the same WITH clause, and also stage variables and global
variables. So a variable declared after the context can use a variable declared before the context, but not the other
way round. You can use all the variables of a WITH clause in all the rules of the rule-set, and only there.
You can write comments and line breaks between the parts of a WITH clause.
WITH EVERY. In the SDK, the definition of some nodes and fields includes a condition: they cover only the XML
elements of the notice that meet it. For example, the SDK node ND-BuyerReviewComplainants is an XML element
efac:AppealRequestsStatistics whose statistics code comes from the codelist review-type.
-
WITH ND-BuyerReviewComplainantschecks the rules only for the elements that meet this condition. -
WITH EVERY ND-BuyerReviewComplainantschecks them for every elementefac:AppealRequestsStatisticsat that place in the notice, whatever its code, and also when the code is missing.
In the rules, EFX reads the fields and nodes as without EVERY. EVERY leaves out only the condition of the SDK
definition of the context: a predicate written in the WITH clause still applies.
You use EVERY where a rule must also apply to the elements that do not meet the condition of the SDK definition,
for example an element whose code is missing.
You write the keywords WITH and EVERY in upper case. In lower case, every starts a quantified expression (see
Quantified expression).
The WITH clause of a rule-set has the same structure as the context declaration of a template line (see
Context declaration).
Restrictions
-
A
WITHclause declares exactly one context. -
The context is a field or a node:
WITH / …is an error. For the root of the notice, writeND-Root. -
You must declare a variable before you use it. Its name must differ from the names of the other variables of the
WITHclause, of the stage variables of the stage, and of the global variables. -
In a
WITHclause, you can call a dynamic function only as the value of a dynamic variable.
Examples
WITH BT-13-Text
ASSERT string-length(BT-13-Text) <= 100
AS ERROR R-B6J-C4R
FOR BT-13-Text
IN *;
A field context. The validation checks the rule once for each occurrence of the repeatable field BT-13-Text.
WITH ND-RepeatableNode[BT-00-Number-In-Repeatable-Node > 0]
ASSERT BT-00-Date-In-Repeatable-Node is present
AS ERROR R-M3C-U8N
FOR BT-00-Date-In-Repeatable-Node
IN *;
A node context with a predicate. The validation checks the rule only for the repeatable nodes whose number is greater than zero.
WITH ND-Root
ASSERT BT-00-Text is present
AS ERROR R-K7P-M2Q
FOR BT-00-Text
IN *;
The root of the notice as context.
WITH text*:$all-texts = BT-00-Text-In-Repeatable-Node,
ND-RepeatableNode,
number:$length = string-length(BT-00-Text-In-Repeatable-Node)
ASSERT BT-00-Text-In-Repeatable-Node is unique in $all-texts
AS ERROR R-Y2N-G7S
FOR BT-00-Text-In-Repeatable-Node
IN *;
ASSERT $length <= 200
AS WARNING R-D4K-P9M
FOR BT-00-Text-In-Repeatable-Node
IN *;
Variables before and after the context. $all-texts, declared before the context, holds the values of the field in
all the repeatable nodes of the notice. EFX computes $length, declared after the context, for each repeatable
node.
WITH context:$node = ND-RepeatableNode
ASSERT count(BT-23-Text[BT-23-Text == $node::BT-00-Text-In-Repeatable-Node]) <= 1
AS WARNING R-F5V-T6B
FOR BT-23-Text
IN *;
A context variable. Inside the predicate, the context is an occurrence of BT-23-Text. The context variable refers
to the repeatable node under evaluation.
WITH ND-RepeatableNode,
dynamic:$known = ?is-known-organisation(BT-00-Text-In-Repeatable-Node)
ASSERT $known
AS ERROR R-A8Q-H3W
FOR BT-00-Text-In-Repeatable-Node
IN *;
A dynamic variable, which holds the result of a call to the dynamic function ?is-known-organisation for each
repeatable node (see
Dynamic function declaration).
WITH EVERY BT-01-SubSubNode-Text
ASSERT BT-01-SubSubNode-Text != ''
AS ERROR R-X3F-N8W
FOR BT-01-SubSubNode-Text
IN *;
The rule applies to every XML element of the kind of BT-01-SubSubNode-Text, also to those that do not meet the
condition of its definition in the SDK.
validation/stage-1m.efx)WITH EVERY ND-BuyerReviewComplainants
ASSERT BT-712(b)-LotResult is present
AS ERROR R-WA6-APY
FOR BT-712(b)-LotResult
IN *;
A rule that requires a number in every XML element of statistics of its kind.
EFX-1 had no rule-sets. In the field metadata, the context of each condition came in braces before the expression,
for example {ND-Root} ${BT-00-Text is present}. WITH EVERY is new in EFX-2.
|
See also: Rule-set, Scope of variables