MULTEXT - Document MQL2. SgmlQL reference/Operators.


Within

This operator takes an SGML element as argument, and produces a list composed of a subset of its sub-elements. Traversal is a pre-order traversal: nodes are visited from the leaves to the root and from left to right.

Prototypes

list <-- selection within element

list <-- selection as varname within element where boolean

The second variant returns only elements for which boolean is TRUE. Varname is a variable which is mapped to each visited node, and which can be used in boolean.

Selection follows the prototype:

every | top | bottom | first [ level-range ] [ names ] [ as varname ]

where:

level-range ::= [ min [ : max ] ]
names ::= [ excluding ] name-set

The first, mandatory, keyword (every, top, bottom orfirst) is used to specify (and possibly restrict) the nodes visited during the tree traversal:

every
All matching nodes are visited recursively. Recursive sub-elements are all visited.
top
Only the top-most matching node of recursive sub-elements is visited.
bottom
Only the lowest matching node of recursive sub-elements is visited.
first
Only the first matching sub-element is visited.

Level-range is optional, and can be used to restrict traversal to a specific level in the SGML tree of element, or a range from the min level to the max level. For instance, the expression selection every [3:10] visits all the nodes of the tree between the levels 3 and 10.

Names can be used to specify the generic identifiers of the nodes which will be visited, or on the contrary which will not be visited (using the keyword excluding). For instance:

every DIV within $e visits recursively all DIV nodes of $e.

bottom DIV within $e visits the DIV nodes of $e which do not contain themselves DIV nodes.

first [3] {P,Q} within $e visits the first P or Q nodes encountered at level 3 of $e.

Finally the as clause can be used to assign to a local variable varname the value of each node visited. This local variable can other parts of the query, especially the where clause. For instance:

The expression every DIV as $div within $e where $div->TYPE eq "chap" visits recursively all the DIV nodes of $e that contain an attribute TYPE whose value is chap.

Examples




| Top | Next | SgmlQL reference | LPL/CNRS | MULTEXT

Copyright © Centre National de la Recherche Scientifique, 1997.