> > > Internal evaluation error: context is missing for node 1.1.3.27.2.2 !
>
> This can sometimes be a sign of user error; but it could also indicate that
> an insidious and long-lived bug, only recently eradicated from the trunk,
> has crept back into (or has been retained in) the dln code.
Well, the message indicates a problem in eXist's internal processing.
It may appear in different contexts, but especially general
comparisons or not(). Most of these contexts should be fixed and the
error has become quite rare. However, it is possible that David has
found another processing trap somewhere.
It could also be a user error (though we should try to throw a correct
error message then). Looking at the stack trace and the corresponding
query expression should tell us more.
Wolfgang

Pierrick Brihaye wrote:
Wasn't david rather looking for distinct countries *after* normalization
Something like :
distinct-values(
for $country in $manuscripts//repositCountry
return normalize-space($country)
)
Absolutely right. I fell into the characteristic debugging trap of focussing
on the core problem while losing sight of the point behind the code. Result:
a half-baked solution that removed both the error and the intended outcome
that the buggy code was aimed at producing.
Of course, it was 1.30 am over here. Next time the cat sets off the burglar
alarm in the wee small hours, I will try to resist the temptation to turn
on my monitor...
Michael Beddow

David J Birnbaum wrote:
> distinct-values($manuscripts//repositCountry/normalize-space(text()))
XPaths have to be made up of steps composed of axes and node-tests (plus
maybe predicates). You can't insert a function where the grammar allows only
a node-selector. It was pretty naughty of eXist to let you get away with
that, if it once did so.
But there's a further snag, which you allude to in your posting.
Before we get to that, let's make things a bit clearer by dispensing with
the text() node test, which in most instances is either redundant or
productive of undesired effects. manuscripts//repositCountry will get you a
concatenation of all the text nodes below that element, which is probably
what you want. If there's only one text node, then specifying text() won't
do anything at all, and if there's more than one text node, then it will get
you the first one only, which is hardly ever what people want. In addition,
along with node(), it exemplifies a very odd feature of XPath, namely that
these two node tests have apparently the syntax of function calls. Only
apparently though: it's an error to try to put anything into the
parentheses. And this oddity means that the incorrect placing of a true
function, as in your example, doesn't stand out as clearly as it otherwise
might.
So, with text() jettisoned, even if we tried to re-write as
[WRONG] normalize-space(distinct-values($manuscripts//repositCountry))
we would get an error unless the XPath returned a sequence with zero or one
only members. As soon as it selects a sequence with more than one member,
the XPath would be passing more than one parameter into normalize-space(),
which violates its prototype(s)
So, you need to rejig your code so that normalize-space() is applied only to
a single string item (or a single node that has been cast to a string)
Plainly, the details will depend on the broader context, but one approach
would look in outline like this:
for $country in distinct-values($manuscripts//repositCountry)
return normalize-space($country)
Now there, the XPath itself may return multiple nodes, but the FLOWR
construct causes only one of them at a time to be bound to $country. Hence
you can safely apply normalize-space() to that value.
Michael Beddow