[xquery-talk] Add value to result before a for loop
Gary Larsen
gary.larsen at envisn.com
Wed Jul 18 06:59:29 PDT 2012
Thanks for everyone's suggestions!
Using this syntax:
let $hdr := concat('Id', codepoints-to-string(9), 'Name',
codepoints-to-string(10))
let $body := for $i in $doc/item return
concat($i/id, codepoints-to-string(9), $i/name, codepoints-to-string(10))
return string-join($hdr, $body)
I'm getting a error due to the results of the for loop:
The actual cardinality for parameter 2 does not match the cardinality
declared in the function's signature: string-join($arg as xs:string*,
$separator as xs:string) xs:string. Expected cardinality: exactly one, got
2.
Gary
-----Original Message-----
From: David Carlisle [mailto:davidc at nag.co.uk]
Sent: Wednesday, July 18, 2012 9:52 AM
To: Gary Larsen
Cc: talk at x-query.com
Subject: Re: [xquery-talk] Add value to result before a for loop
On 18/07/2012 14:04, David Carlisle wrote:
>
>
> for is just an expression
true
so you could for example use
false sorry, you can't use concat here, the verions below using
string-join are OK though.
> concat($hdr,for $i in ......)
>
> of course in this simple example you don't need the variable at all as
> $hdr is already just a call to concat you could return the single
> expression
>
> concat('Id', codepoints-to-string(9), 'Name',
> codepoints-to-string(10),
> for $i in$doc/item return
> concat($i/id, codepoints-to-string(9), $i/name, codepoints-to-string(10)
> )
>
> or more simply
>
> string-join(
> ('Id Name',$doc/item/concat(id,' ',name)),'
')
>
> the let and for clauses aren't really needed,
>
> David
>
>
>
>
--
google plus: https:/profiles.google.com/d.p.carlisle
________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________
More information about the talk
mailing list