element (element-name (| element-name)* | #implied) condition?
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
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:
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:
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
If you have many elements for which you want the same processing, you can use an
element #implied rule:
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:
Much of the processing you want to do in an element rule depends on information about the current state of the parse. The following information is available on the current parse state (some of these items do not apply to XML):
of open elementlet you refer to the current element and it parents
preparent islet you test the identity of the current element and its parents
previous islets you test the identity of the preceding element
last subelement islets you test the identity of the preceding subelement
open element islets you test if an element is open
name ofreturns the name of the specified element
"%q"returns the name of the current element
attributereturns the value of a specified attribute
attributesshelf contains the names and values of all the attributes of the specified element
usemap islets you determine if the current element has a short reference map
content islets you determine the type of content model the current element has
occurrencereturns the number of consecutive occurrences of the current element type
childrenreturns the total number of children of a specified element seen so far
status islets you determine why an element was allowed in a content model
The above keywords can be combined in all the meaningful combinations, so that you can say, for example:
output attribute "type" of parent of ancestor "listitem"