Validation makes sense only in a given context. Validating a name element inside a user element checks that it contains first and last elements; while validating a name element inside an article element checks that it contains a string.
In addition to keeping track of the types of variables, the static environment contains a validation context. Initially, this context is set to global. During static analysis, when an element constructor with a given name is entered, the context is extended by that element name within the constructor. For example, consider the query in Listing 4.10, which constructs a user element, omitting the first name if it is too long, or the rating if it is too low.