Reputation: 2269
{
for $movie in distinct-values(doc("movies.xml")/movies/movie)
where count(doc("movies.xml")/movies/movie[title=$movie/title]) = count(distinct-values(doc("movies.xml")/movies/movie/source))
return
<title> {$movie/title} </title>
}
In this particular query I am tryin to : Find movie titles that are offered from all sources in the "movies" document. I am getting an error on the line of the where clause. the error is : Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtomicType
Upvotes: 0
Views: 813
Reputation: 11773
The problem is that distinct-values()
returns distinct string values, so you are trying to use an xpath expression on a string. $movie/title
evaluates to (xs:string)/title
which is invalid and throws an exception.
But the way I understand your goal, I don't think that query will return the results you want. Try this solution for returning movie titlea that are offered from all sources:
let $sources-distinct-all := count(distinct-values(doc("movies.xml")/movies/movie/source))
for $title in distinct-values(doc("movies.xml")/movies/movie/title)
let $sources-distinct-movie := count(distinct-values(doc("movies.xml")/movies/movie[title eq $title]/source))
where ($sources-distinct-all eq $sources-distinct-movie)
return $title
Upvotes: 0