Hi
I have a question about the following XQuery:
declare namespace ft=“http://www.w3.org/2002/04/xquery-operators-text”
for $dbRecord in input()/Records/Record
for $dbSet in $dbRecord/Sets/Set
where
$dbRecord/Year <= 1995
and $dbRecord/Year >= 1995
and $dbRecord/Sets/Set/Term = ‘First’
and (ft:text-contains($dbSet/ProgramTitle, ‘testing’)
or ft:text-contains($dbSet/SubjectTitle, ‘testing’)
or ft:text-contains($dbSet/Department, ‘testing’))
return $dbRecord
sort by (Sets/Set[1]/SubjectCode, Year descending)
if the a record have two set that match the where cause, it return the record twice, is it able to have distinct value of $dbRecord
Thx!!
Use the distinct-values() function.
Regards,
Guenter Grossberger
Software AG
Hi
i have try the distinct-value for it do not allow me to use in the for statement i.e.
for $dbRecord in distinct-values(input()/Records/Record) …
The return is “Type exception: non-atomic type in element/attribute”
Element/Attribute: Record; line 1, column 18:
Have you experimented with using a LET instead of the FOR on $dbSet?
Instead of:
for $dbSet in $dbRecord/Sets/Set
use:
let $dbSet := $dbRecord/Sets/Set
Douglas Kelly,
Principal Consultant
Software AG, Inc
Sacramento, California
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