The select/from/where is used to create a list of elements.
Prototype
list <-- select query from v1 in list1 [, v2 in list2]* [ where boolean ] where query and boolean are expressions depending on v1, v2, ...
The value of such a query is a list L built as follows :
let L be the empty list, for each element v1 of list1 for each element v2 of list2... if the value of boolean is true then append the value of query to L
As classical with SQL the select_from_where is a nested join of lists list1, list2, ... followed by a restriction followed by a projection.
This operator can be obviously used with more than two lists.
Example a clause from with two variables:
$var1 . "/" . $var2 . "\n" from $var1 in [A,B,C] , $var2 in [1,2,3,4] ;
A/1
A/2
A/3
A/4
B/1
B/2
B/3
B/4
C/1
C/2
C/3
C/4
Others practical examples:
Set the variable divs to contain the list of upper level divisions of $myfile:
global $divs = top DIV within file $myfile ;Output the number of paragraphs in each upper level division of the document:
select count(every P within $d) . " " from $d in $divs ;3 6 4Output the number of paragraphs in each sub-division of each upper level division of the document:
select count(every P within $d) . " " from $d in ( select top DIV within $s from $s in $divs ) ;3 3 3 2 2Output number and date of each upper level division that contains a note:
select top {NUM, DATE} within $d from $d in $divs where not(empty(first NOTE within $d)) ;<NUM TYPE="wqref"> 2579/91 </NUM><DATE> 14 November 1991 </DATE>Output the number and date of each upper level division that contains a note, excluding the tags:
select text( (top {NUM, DATE} within $d), " -- " ) from $d in $divs where not(empty(first NOTE within $d)) ;2579/91 -- 14 November 1991Search for all upper level divisions that contain a paragraph matching a European country name; output the number of the question and the country code:
global $countries = top COUNTRY within file "countries.sgml" ; select text(first NUM within $d) . "\t" . $c->CODE . "\n" from $d in $divs, $c in $countries where exists $p in (every P within $d): text($p) match text($c) ;1463/91 DE 1463/91 UK 2579/91 DE 2579/91 NLNote that the computation can be expansive for large lists since the entire cartesian product of list1, list2, etc. is computed.