Skip to content

Commit

Permalink
Added let example to specification.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Nov 10, 2023
1 parent ca6326a commit 0c4664e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions website/content/specification/syntax/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@ During constraint evaluation, each `let` statement MUST be evaluated in encounte

During evaluation, when a variable is bound for a `let` statement, the variables value MUST be set to the result of evaluating the `@expression` using the current node as the Metapath evaluation focus.

For example:

Given the following fragment of a Metaschema module.

```xml
<define-assembly name="sibling">
<define-flag name="name" required="yes"/>
<constraint>
<let var="parent" expression=".."/><!-- stores the parent of the current node -->
<let var="sibling-count" expression="count($parent/sibling)"/>
<expect target="." test="$sibling-count = 3"/>
</constraint>
</define-assembly>
```

And the following document.

```xml
<parent name="p1">
<sibling name="a"/>
<sibling name="b"/>
<sibling name="c"/>
</parent>
<parent name="p2">
<sibling name="x"/>
<sibling name="Y"/>
</parent1>
```

The expect constraint would pass for each `sibling` in the `parent` named "p1", and would fail for each `sibling` in the `parent` named "p2".

## Enumerated values

Additionally, flags may be constrained to a set of known values listed in advance.
Expand Down

0 comments on commit 0c4664e

Please sign in to comment.