Yes, here is an example from the XQuery specification :.
“Joins that combine data from multiple sources into one result are a very important type of query. In this section, we illustrate how several types of joins can be expressed in XQuery. We will base our examples on the following three documents:
- A document called
parts.xml containing many part elements; each part element in turn contains partno and description subelements. - A document called
suppliers.xml that contains many supplier elements; each supplier element, in turn, contains suppno and suppname subelements. - A document called
catalog.xml that contains information about the relationship between suppliers and parts. A catalog document contains many item elements, each of which, in turn, contains partno , suppno and price subelements.
A regular (“internal”) join returns information from two or more related sources, as shown in the following example, which combines information from three documents. The example creates a “descriptive catalog”, obtained from a catalog document, but containing part descriptions instead of part numbers and supplier names instead of supplier numbers. The new catalog is sorted alphabetically by the description of the parts and, secondly, by the name of the supplier. *
<descriptive-catalog> { for $i in fn:doc("catalog.xml")/items/item, $p in fn:doc("parts.xml")/parts/part[partno = $i/partno], $s in fn:doc("suppliers.xml")/suppliers /supplier[suppno = $i/suppno] order by $p/description, $s/suppname return <item> { $p/description, $s/suppname, $i/price } </item> } </descriptive-catalog>
The previous query returns information only about parts that have suppliers and suppliers that have parts. external join is a union that stores information from one or more participating sources, including elements that do not have a corresponding element in another source. For example, a left outer join between suppliers and parts may return information about suppliers that do not have matching parts.
Note that XQuery does not have a standard document () function (this is an XSLT function ) and instead has a doc () function, which is part of " XQuery 1.0 and XPath 2.0 Functions and Operators ".
Chris's answer has at least two errors:
- XQuery is case sensitive - the headwords used in Chris's example will not be resolved by the corresponding XQuery.
- There is no need to prefix standard functions , such as doc (), I just quote the XQuery specification, which has a prefix. Otherwise, in my own code, I would omit the prefix "
fn ". - Function document () is not a standard XQuery / XPath function . Instead, use doc () .
Dimitre novatchev
source share