Reputation: 75
Hi can someone please help me I am not sure why I am getting
"Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtmonicType".
I am trying to group websites by year.
<publications>
{
for $x in distinct-values(//www)
return
<year-Pub>{for $y in //www where $x/year = $y/year
return <year>{$y/*}</year>}</year-Pub>
}
</publications>
Upvotes: 1
Views: 3501
Reputation: 163352
I suspect that you want
<publications>
{
for $x in distinct-values(//www/year)
return
<year-Pub>{for $y in //www[year = $x]
return <year>{$y/*}</year>}</year-Pub>
}
</publications>
Alternatively look at "group by" in XQuery 3.0.
Upvotes: 2
Reputation: 38682
distinct-values(...)
returns a sequence of xs:anyAtomicType
values, eg. strings or numbers, but never XML nodes (node()
). When running on a sequence of XML nodes (which //www
returns), fn:data(...)
is implicitly called for each node to convert it to an atomic value.
In the line for $y in //www where $x/year = $y/year
, you want to perform an axis step starting at $x
, which subsequently is not possible.
As you didn't give any input or description of what exactly you want to achieve, I cannot help you with a working and tested solution, but as a brief sketch to deal with distinct nodes:
distinct-values(//www/year
instead).Upvotes: 1