Marcus,
I second Christian’s recommendation of XQuery for Humanists—I found it to be an excellent introductory text for someone coming to XQuery entirely new. Pricilla’s book is more useful as an authoritative reference
and guide but I think XQuery for Humanists is the better entry point.
To answer your specific question: The message indicates that the expression expected a single item (i.e., a node or atomic value) but it got a sequence of items.
One immediate suggestion is to use “as” qualifiers on all your variables and function parameter declarations. This makes is clear what the intended data type is an allows the XQuery interpreter to detect type
errors at compile time.
So:
let $x as array(*) := …
or
let $tokens as xs:string* := tokenize(‘foo bar’)
Cheers,
Eliot
_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
From:
BaseX-Talk <basex-talk-bounces@mailman.uni-konstanz.de> on behalf of Markus Elfring <Markus.Elfring@web.de>
Date: Monday, April 4, 2022 at 8:27 AM
To: Martin Honnen <martin.honnen@gmx.de>
Cc: basex-talk@mailman.uni-konstanz.de <basex-talk@mailman.uni-konstanz.de>
Subject: Re: [basex-talk] Support for performing queries on query results
[External Email]
> > for $x in $results
> > let $count := $x[1]
>
> Perhaps you want
>
> $x(1)
>
> here to access the first item in the array $x?
Yes. ‒ Thanks that you pointed a typo out.
Thus I adjusted the member access specification.
But I stumble on the message “[XPTY0004] Item expected, sequence found: (1, 1, 1)”
from the query evaluation.
Which script fine-tuning will help then?
Regards,
Markus