[xquery-talk] Problems with string testing in if
Michael Kay
mhk at mhk.me.uk
Tue Jun 1 00:49:57 PDT 2004
This construct:
if ($lang = "no" or "nn" or "nb")
will always be true. It means
if (($lang = "no") or boolean("nn") or boolean("nb"))
The effective boolean value of "nn" is true, so the whole expression is
true.
You want:
if ($lang = ("no", "nn", "nb"))
Michael Kay
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Sjur Nørstebø Moshagen
> Sent: 31 May 2004 21:08
> To: talk at xquery.com
> Subject: [xquery-talk] Problems with string testing in if
>
> Hello,
>
> I'm new to this list, my apologies if this posting is outside the
> intended scope.
>
> I need to query a set of localised documents identified with
> ISO 639-2
> 3-letter codes, and I have written the function cited below
> to convert
> incoming locale strings to the equivalent 3-letter codes for the
> languages in question.
>
> The problem is it does not work as expected. So far I have tried the
> following:
>
> input output
> ----- ------
> no nor
> se nor
> sme nor
>
> The function is:
>
> (: Convert incoming locale strings to 3-letter language codes
> (ISO 639)
> :)
> declare function fn:locale2lang($locale as xs:string) as xs:string
> {
> let $lang := substring-before($locale,'_')
> return
> if ($lang = "no" or "nn" or "nb") then "nor"
> else if ($lang = "se") then "sme"
> else if ($lang = "sv") then "swe"
> else if ($lang = "fi") then "fin"
> else if ($lang = "en") then "eng"
> else if ($lang = "smi") then "sme"
> else if ($lang = "sme" or "sma" or "smn" or
> "smj" or "sms"
> or "sme" or
> "nor" or "swe"
> or "fin" or "eng") then $lang
> else "test" (: the default lang here later, now
> 'test' for debugging
> purposes :)
> };
>
> I'm running the query/function against/in eXist, but I believe it is
> more my understanding of XQuery than anything else that's
> missing, thus
> posting on this list. I would appreciate any help.
>
> Regards,
> Sjur N. Moshagen
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>
More information about the talk
mailing list