Page 1 of 1

string treated as sequence

Posted: Fri Jul 01, 2011 6:28 pm
by sandrocchio_0.1
I've got this function which is giving me some strange errors during debug.
xquery.xq
Severity: fatal
Description: A sequence of more than one item is not allowed as the first argument of string-length() ("Abonnement...", "film...", ...)
Start location: 315:0
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0004
Either the parameters and return value are raw string, so why is treating them as sequence?

Code: Select all


declare function local:normalizeSourceHelper(
$sourceString as xs:string,
$compareString as xs:string)
as xs:string* {
let $result :=
let $arraySource := tokenize($sourceString, ";")
let $arraycompare := tokenize($compareString, ";")
for $source in $arraySource
where $source != ""
return
if(count(
for $compare in $arraycompare
where $compare = $source return (1))=0 )
then concat(data($source), ";")
else
""
return
if(string-length($result)>0) then common:removeLastSemiColumnChar($result)
else $result
};

Re: string treated as sequence

Posted: Fri Jul 01, 2011 10:08 pm
by adrian
Hello,

The error complains about the argument of string-length() being a sequence. The argument is $result. Now look at the value assigned to $result:

Code: Select all

let $result :=
let $arraySource := tokenize($sourceString, ";")
let $arraycompare := tokenize($compareString, ";")
for $source in $arraySource
where $source != ""
return
if(count(
for $compare in $arraycompare
where $compare = $source return (1))=0 )
then concat(data($source), ";")
else
""
It's the result of a for which creates a sequence. Ir may be a sequence of strings, but it's still a sequence, hence the problem.

Regards,
Adrian

Re: string treated as sequence

Posted: Tue Jan 03, 2012 6:15 pm
by sandrocchio_0.1
thanks!