Confusing error using GROUP BY

Sunday, 23 March 2014 · 2 messages
CD
Charles Duffy23 Mar 2014 03:44 #
Howdy -- I've run into a somewhat confusing error message using GROUP BY in BaseX 7.8.1, while trying to answer a question on StackOverflow ( http://stackoverflow.com/questions/22585865/grouping-with-counts-in-xquery). Against the database at http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml, I'm running the following query:
for $line in //SPEECH/LINE
let $speaker := $line/../SPEAKER/text()[1]
group by $speaker
return <speaker name="{$speaker}" count="{count($line)}"/>
...and receiving the error: [XPTY0004] Single item expected, (db:open-pre("hamlet",748), db:open-pre("hamlet",750)) found. I've gone over the GROUP BY docs several times, and not seeing my error in the above. Could someone enlighten?
LQ
Liam R E Quin23 Mar 2014 07:08 #
Quoted text · Charles Duffy · 1 line
On Sat, 2014-03-22 at 20:44 -0500, Charles Duffy wrote:
I'd guess:
Quoted text · Charles Duffy · 1 line
> let $speaker := $line/../SPEAKER/text()[1]
A list of all text nodes that are the fist child of SPEAKER elements? Try ($line/../SPEAKER/text())[1] if you want the first text node in the list. Maybe you have a SPEAKER element with comments, processing instructions or other elements inside, or maybe the container of $line has more than one SPEAKER element sometimes.
Yes,
<SPEECH>
<SPEAKER>CORNELIUS</SPEAKER>
<SPEAKER>VOLTIMAND</SPEAKER>
<LINE>In that and all things will we show our duty.</LINE>
</SPEECH>
-- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

⚡Generated with XQuery