[xquery-talk] Problems with string testing in if
Sjur Nørstebø Moshagen
sjur.moshagen at kolumbus.fi
Tue Jun 1 12:44:38 PDT 2004
På 1. jun. 2004 kl. 10.50 skrev Sjur Nørstebø Moshagen:
> Thanks to all on the list for helping me and being patient with my
> ignorance. I will contact the eXist developer with a bug report.
The bug was in fact in my function, eXist works correctly in all cases.
More precisely the following expression was at fault:
let $lang := substring-before($locale,'_')
The problem was that I assumed without checking that substring-before
would return the _whole_ string if it didn't find the second argument
in the first, whereas the spec says:
"If the value of $operand1 does not contain a string that is equal to
the value of $operand2, then the function returns the zero-length
A zero-length string of course didn't match any of the tests, thus the
whole function would only return the last else clause for all simple
locales (e.g. en, no, nn, nb, sv, fi, etc.). Locales containing a
country part (fi_FI, en_GB, etc) would return the correct string, as
evidenced by the test from Philippe Michiels.
One correct version looks like:
let $lang := if (contains($locale,'_') ) then
substring-before($locale,'_') else $locale
Sorry for bothering you.
More information about the talk