I am trying to find employees who work on projects located in Houston but the department the project is housed in is not located in Houston. I was trying to model the expression after this example of FLWOR expressions but the query doesn't return anything and it should return results.
edit: Here is the input.
xquery
let $doc := doc("~path/company.xml")
for $e in $doc//employee,
$d in $doc//department,
$p in $doc//projects
where $d/locations[location!="Houston"]
and $p/project[plocations="Houston"]
return <e>{$e/fname}{$e/lname}{$e/address}</e>
/
One for
clause is enough; otherwise, you'll iterate over all employees several times:
let $doc := doc(...)
for $e in $doc//employee
let $p := $doc//project[@pnumber = $e/projects/worksOn/@pno]
where $p[plocation = 'Houston']
and $doc//department[@dno = $p/@controllingDepartment]
[not(locations/location = 'Houston')]
return <e>{ $e/fname }{ $e/lname }{ $e/address }</e>
A single XPath 2.0 expression can select all wanted employees:
/*/employees
/*[projects/*/@pno
=
/*/projects/*
[plocation eq 'Houston'
and
boolean
(for $dn in @controllingDepartment
return
/*/departments/*
[@dno eq $dn
and
not(locations/location
=
'Houston'
)
]
)
]/@pnumber
]
Typo: and $p/project[plocation="Houston"]
You had an "s" too much: was plocations
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With