Hi,
If you do not want a ?Record? element being multiple times in you result set if it has multiple ?Set? elements fulfilling the ?where? clause you have to drop the second ?for? clause and add an existence check for ?Set? elements fulfilling the ?where? clause.
An according query may look like this:
for $dbRecord in input()/Records/Record
let $x := for $dbSet in $dbRecord/Sets/Set
where (ft:text-contains($dbSet/ProgramTitle, ‘testing’)
or ft:text-contains($dbSet/SubjectTitle, ‘testing’)
or ft:text-contains($dbSet/Department, ‘testing’))
return $dbSet
where
$x
and $dbRecord/Year <= 1995
and $dbRecord/Year >= 1995
and $dbRecord/Sets/Set/Term = ‘First’
return $dbRecord
sort by (Sets/Set[1]/SubjectCode, Year descending)
The idea of the query is to collect for each ?Record? element all ?Set? elements in $x and performing a non empty check on $x. Since $x is bound to a node sequence you can do this by just adding $x to the ?where? clause.
Best regards,
Thorsten Fiebig
#Tamino#API-Management#webMethods