Q:How to find the right flight


I do have the following schema (not complete and not exactly the same).

<xs:element name=“Flight”>
<xs:sequence maxOccurs=“unbounded”>
<xs:element name=“company”>
<xs:attribute name=“main” type=“xs:boolean”/>
<xs:attribute name=“flightnumber” type=“xs:string”/>


So we could have a document like this

This means that we have a flight which can be shared by more than one company.

Now I would like to find every main flight that is also a none main flight, i.e. main=“false” so the next trivial example will match the above example:

I thought that the next XQuery would do the job:

for $flight1 in input()/flight,
$flight2 in input()/flight
where $flight1/company[@main=“true”]/@fltnr=$flight1/company[@main=“false”]/@fltnr

but that does not work (using Tamino

Could someone help me further?


Hi Rudolf,

The reason I think this doesn’t work is that you can’t mix X-Query and XQuery together. This means the where clause needs to test @main=‘true’, @main=‘false’ and the two flight numbers separately. This can be done in a single where clause connecting the three tests with ‘and’, i.e.

for $x in input()/flight/company,
$y in input()/flight/company
where $y/@main = ‘false’ and $x/@main=‘true’ and $x/@fltnr = $y/@fltnr
return $x/…

Hope this helps.

Stuart Fyffe-Collins
Software AG (UK) Ltd.

Hi Rudolf,

actually your query does the job (if you correct one typo), and it is legal in XQuery o have path expressions wherever expressions are allowed.
You had $flight1 at the right hand side of the = operator rather than flight2. The following query

for $flight1 in input()/flight,
$flight2 in input()/flight
where $flight1/company[@main=“true”]/@fltnr=$flight2/company[@main=“false”]/@fltnr

- <xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>



because both flights have an entry with main=“true” that has a corresponding main=“false” in the other entry