12.4.1 Construction Rules
[161] construction-rule = query-construction-rule | id-construction-rule | element-construction-rule | root-construction-rule | default-element-construction-rule
The construction-rules in a style-specification (see section 7.1, DSSSL Document Architecture) specify how a node in the source grove is to be processed. Each construction-rule matches some (possibly empty) set of the nodes in a source grove. Refer to section 9, Groves for information about groves and their use in this International Standard.
A construction-rule includes a construct-expression, which is an expression returning an object of type sosofo. A sosofo is a specification of a sequence of flow objects to be added to the flow object tree. See section 12.4.3, Sosofos. When a construction-rule is applied to a node, its construct-expression is evaluated.  The node to which it is applied becomes the current node for the evaluation of the construct-expression.
The most specific construction-rule (as defined below) that matches the node is applied to the node.


Processing a node has no side-effects; it just returns a value.
A node is processed with respect to a current processing mode. In addition to named processing modes that are specified with mode-construction-rule-groups, there is an initial processing mode that is unnamed. construction-rules not in any mode-construction-rule-group can match nodes both when the processing mode is the initial processing mode and when it is a named processing mode.
A flow object tree is constructed from a source grove by processing the root node of the source grove in the initial processing mode; the flow objects specified by the resulting sosofo are added as children of the root of the flow object tree.  The flow objects specified by this sosofo shall all be unlabeled, and shall either be all of class scroll, or shall be all of class page-sequence or simple-page-sequence.
[162] mode-construction-rule-group = (mode mode-name construction-rule*)
[163] mode-name = identifier
A construction-rule in a mode-construction-rule-group matches a node only when the current processing mode is mode-name.
The relative specificity of construction-rules is determined as follows:

•  A construction-rule in a mode-construction-rule-group is more specific than any construction-rule not in a mode-construction-rule-group.

•  Among construction-rules that have the same specificity according to the preceding rule, a construction-rule in one part of a style-specification is more specific than any construction-rule in a subsequent part (see section 7.1, DSSSL Document Architecture).

•  Among construction-rules that have the same specificity according to the preceding rules, each of the following is more specific than the next:

•  query-construction-rule

•  id-construction-rule

•  element-construction-rule

•  default-element-construction-rule

•  root-construction-rule

•  A query-construction-rule is more specific than another query-construction-rule with a lesser priority.

•  An element-construction-rule with a qualified-gi containing two or more gis is more specific than another element-construction-rule with no qualified-gi or with a qualified-gi containing fewer gis.
It shall be considered an error if there are two or more equally specific construction rules that match the node.
In addition to construction-rules explicitly specified in style-language-bodys, there is an implicit default construction-rule.  The default construction rule matches any node in a source grove but is less specific than any explicitly specified construction-rule. The result returned by the default construction-rule shall depend on the type of node to which it is applied:

•  for a node of class sgml-document, it shall return (process-children).

•  for a node of class element, it shall return (process-children).

•  for a node with a char property, it shall return (make character).

•  for a node of class attribute-assignment, it shall return (process-children).

•  for any other kind of node, it shall return (empty-sosofo).
[164] query-construction-rule = (query style-query-expression construct-expression priority-expression?)
A query-construction-rule matches any node in the node-list returned by the style-query-expression. query-construction-rules require the query feature.
[165] style-query-expression = expression
A style-query-expression shall return an object of type node-list.  Within a style-query-expression, the current-root and current-node procedures both return the grove root of the grove being processed.
[166] construct-expression = expression
A construct-expression shall return an object of type sosofo. When the query feature is enabled, within a construct-expression, the current-node procedure shall return the current node.
[167] priority-expression = expression
The priority-expression specifies the priority of the query-construction-rule. It shall evaluate to a number. If the priority-expression is omitted, then the priority shall be 0.  Bigger numbers indicate higher priorities.
[168] element-construction-rule = (element (gi | qualified-gi) construct-expression)
[169] gi = string | symbol
[170] qualified-gi = (( gi+ ))
An element-construction-rule matches any node of class element that matches the gi or qualified-gi. A node matches a gi if its generic identifier is equal to the string or symbol. A node matches a qualified-gi if it matches the last gi in the qualified-gi, and its parent matches the next to last gi, and so on for each gi in the qualified-gi.
[171] default-element-construction-rule = (default construct-expression)
A default-element-construction-rule matches any node of class element.
[172] root-construction-rule = (root construct-expression)
A root-construction-rule matches any node of class sgml-document.
[173] id-construction-rule = (id unique-id construct-expression)
[174] unique-id = symbol | string
An id-construction-rule matches any node of class element that has a unique identifier equal to unique-id.