element

rule

element qualifier

Syntax
element (element-name | element-name-list | #implied) condition?

        
or
element (of element-expression)?
    


Purpose

You use element rules to process elements in XML or SGML data. For instance, the following rule processes a "price" element:

  element "price"
     output "$%c"

Every element rule must call "%c" or suppress once and only once. The call may occur in a function called from the rule.

You can have more than one element rule for an element, provided only one of them can be selected at any given time:

  element "price" when parent is "widget"
     ...
  
  element "price" when parent is "dohickey"
     ...

Note that, unlike find rules, where the first matching rule is fired, even if multiple rules could match the data, element rules require that there always be one and only one selectable rule in all circumstances. Therefore, the following rules will cause an error for a "price" element whose parent is "widget", since either rule could be selected:

  element "price" when parent is "widget"
     ...
  
  element "price" 
     ...

You can have a single rule fire for more than one element type by specifying the list of element names in parentheses separated by the or operator |:

  element ("price" | "cost")
     output "$%c"

If you have many elements for which you want the same processing, you can use an element #implied rule:

  element #implied
     suppress

You can qualify an element #implied rule, just like any other element rule. For instance, you can provide a rule for all the subelements of a paragraph:

  element #implied when parent is "p"
     ...

As an element expression

You can also use element in an element expression, to specify the current element in the currently-active parse. In the absence of element qualifiers, element tests and queries typically operate on the current element, and so of element is usually redundant. It can, however, be used to clarify intent.