On my website (eXist-db, Xquery 3.1) users can download dynamically-generated documents. I have successfully implemented this for .pdf, .xml, and .zip files.
Now I am trying to get .csv outputs into serializing, but failing.
I get the following error:
checking function parameter 1
The actual cardinality for parameter 1 does not match the cardinality declared in the function's signature: . Expected cardinality: zero or one, got 2.
The error is triggered in the function local:download() in the line let $binaryresult := util:string-to-binary($result,'UTF-8')
I thought I could pass a series of strings to the serializer, and then the serializer would effectively out each item into a line in the .csv document (creating a line return).
Evidently I'm approaching the serialization of .csv wrong, but haven't been able to figure out how t correct this. The problem is fundamentally "how to output data rows to a CSV with line returns".
declare option exist:serialize "method=text media-type=text/csv";
declare function local:output-csv()
{
$output := (concat("title1", ",", "title2"),concat("data1a", ",", "data2a"),concat("data1b", ",", "data2b"))
return $output
};
declare function local:download()
{
let $filename := "search_results.csv"
let $result := local:output-csv()
let $binaryresult := util:string-to-binary($result,'UTF-8')
return
response:stream-binary($binaryresult,'text/csv',$filename)
};
Thanks in advance for help with this.