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
- first within file $myfile;
<CESHEADER VERSION="2.1"><FILEDESC><TITLESTMT><H.TITLE> This is an artificial example extracted from ...(full result)...first TEXT within file $myfile; <TEXT LANG="en"><BODY><DIV TYPE="Article" LANG="en"><HEAD> WRITTEN QUESTION <ABBR> ...(full result)...every DATE within file $myfile; <DATE> 16 July 1991 </DATE> ...(full result)...every {NUM, DATE} within file $myfile; <NUM TYPE="wqref"> 1463/91 </NUM><DATE> 16 July 1991 </DATE><DATE> ...(full result)...global $heads = top HEAD within file $myfile; select top excluding {#PCDATA, NAME, ABBR} within $h from $h in $heads ;<NUM TYPE="wqref"> 1463/91 </NUM><DATE> 16 July 1991 </DATE><DATE> ...(full result)...top within (first PUBLICATIONSTMT within file $myfile); <DISTRIBUTOR> Multext project </DISTRIBUTOR><PUBADDRESS> Laboratoire Parole et Langage, CNRS/Université de Provence, 29, avenue Robert Schuman, 13621 Aix-en-Provence cedex 1, France </PUBADDRESS><AVAILABILITY> public </AVAILABILITY><PUBDATE> 1997 </PUBDATE>