我想生成csv文件。下面的代码创建了csv文件,但是无法为每个新行追加数据行。
我错过了什么吗?
以下是代码:
xquery version "1.0-ml";
let $filename := "D:\csv-reports\test.csv"
let $directory-query := cts:directory-query("/searcdoc/")
let $uris := cts:uris((), (), $directory-query)
for $uri in $uris
let $additional := doc($uri)/searcdoc/access/additional/text()
let $des := doc($uri)/searcdoc/std/text()
let $option := <options xmlns="xdmp:save"><method>text</method></options>
let $results := text{((fn:string-join(($uri, $des, $additional), ",")), " ")}
return
xdmp:save($filename, $results, $option)
答案 0 :(得分:1)
我认为你只需要重新安排一下代码。试试这个:
xquery version "1.0-ml";
let $filename := "D:\csv-reports\test.csv"
let $directory-query := cts:directory-query("/searcdoc/")
let $option := <options xmlns="xdmp:save"><method>text</method></options>
let $uris := cts:uris((), (), $directory-query)
let $lines :=
for $uri in $uris
let $additional := doc($uri)/searcdoc/access/additional/text()
let $des := doc($uri)/searcdoc/std/text()
return fn:string-join(($uri, $des, $additional), ",")
return
xdmp:save($filename, text{ fn:string-join($lines, " ") }, $option)
已修改,可将"\n"
更改为" "