1.4. X-script sections and events

The X-script of an element, attribute, or text node may contain several sections. So far we described the quantifier of an item and also the method used to validate the text value of an attribute or text node. This pair is called the validation section(note that specifying a validation method is not allowed in the element X-script). The other sections are introduced by keywords which indicate the situation or event when the code of a section will be invoked. See the following table:
match          called before processing the item. The called code must return a parsed result
               or a boolean value. The item is accepted for further processing if no error is
               reported or if result value is true.
onTrue         invoked if the validation method of an attribute or text node didn't recognize an error.
onFalse        invoked if the validation method of an attribute or text node recognized an error.
default        invoked if the attribute or the text node is missing. The invoked code must return
               the required value.
init           invoked when the processing of the item started (before other actions).
onElementStart invoked when all attributes were processed, but before the processing of child nodes
               of the processed element.
finally        invoked at the end of the processing of the element.
onAbsence      invoked if the item is missing (never invoked if "default" is specified).
create         invoked only in the construction mode (will be described later).
options        set parameters used when an item is processed.
Example:
<Book xd:script="init outln('Book processing started'); finally outln('finished');"
      ISBN="int(10000000, 999999999); onTrue outln('ISBN is OK'); onFalse outln('ISBN error');"
      published="optional gYear(); onAbsence outln('date missing');" > 
  <Author xd:script="occurs *"> string(); onTrue outln('Author: ' + getText()); </Author>
  <Title> string(); onTrue outln('Title: ' + getText()); </Title>
</Book>