HOME

TheInfoList



OR:

The programming language
XQuery XQuery (XML Query) is a query language and functional programming language designed to query and transform collections of structured and unstructured data, primarily in the form of XML. It also supports text data and, through implementation-sp ...
defines FLWOR (pronounced 'flower') as an expression that supports iteration and binding of variables to intermediate results. FLWOR is an acronym:
FOR For or FOR may refer to: English language *For, a preposition *For, a complementizer *For, a grammatical conjunction Science and technology * Fornax, a constellation * for loop, a programming language statement * Frame of reference, in physics * ...
, LET, WHERE, ORDER BY, RETURN. FLWOR is loosely analogous to
SQL Structured Query Language (SQL) (pronounced ''S-Q-L''; or alternatively as "sequel") is a domain-specific language used to manage data, especially in a relational database management system (RDBMS). It is particularly useful in handling s ...
's SELECT-FROM-WHERE and can be used to provide join-like functionality to
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
documents. *''for'' creates a sequence of nodes *''let'' binds a sequence to a variable *''where'' filters the nodes on a boolean expression *''order by'' sorts the nodes *''return'' gets evaluated once for every node


Example

for $d in doc("depts.xml")//deptno let $e := doc("emps.xml")//employee eptno = $d where count($e) >= 10 order by avg($e/salary) descending return First column of the XQuery request shows the for, let, where, order by and return keywords of the FLWOR paradigm. In plain English, this could be read as ''"Get all departments that have more than ten employees, order these departments by decreasing average salary, and return a report of department numbers, head counts and average salary in each big department"''. The result could look like: 17 25 12500 24 18 11327 3 32 10725


Example using Microsoft SQL Server

DECLARE @xml XML SET @xml = ' 42 27 a b ' SELECT x.y.query('for $s in self::node() return $s//item_1/text()') as i, x.y.query('for $s in self::node() return $s//item_2/text()') as j FROM @xml.nodes('/root_element') AS x(y);


References


External links


W3C XML Query (XQuery) - FLWOR Expressions




* https://web.archive.org/web/20111008001258/http://w3schools.com/xquery/xquery_flwor.asp XML {{Compu-lang-stub