通过 XQuery 将引号添加到 CSV
Add quotes to CSV through XQuery
我有一个 XML 的片段,我试图将其转换为逗号分隔值行,每个逗号分隔值都用引号引起来。
这就是我要改造的。
<xml>
<books>Harry Potter,The Hobbit,The Lord Of The Rings</books>
</xml>
这就是我想要的。
"Harry Potter","The Hobbit","The Lord Of The Rings"
我试过了
let $args := $context//xml/books
let $lines := tokenize($args, ',')
return
string-join(concat("'", $lines, "'"), ",")
不幸的是我得到了这个错误。有人可以帮忙吗?
不允许将超过一项的序列作为 concat() 的第二个参数 ("Harry Potter","The Hobbit","The Lord Of The Rings")
您正在将标记序列的字符串序列化版本与开始和结束引号连接起来。相反,您需要遍历您的标记,并对每个标记应用引号。
string-join(
for $l in $lines
return concat('"', $l, '"'),
",")
我有一个 XML 的片段,我试图将其转换为逗号分隔值行,每个逗号分隔值都用引号引起来。
这就是我要改造的。
<xml>
<books>Harry Potter,The Hobbit,The Lord Of The Rings</books>
</xml>
这就是我想要的。
"Harry Potter","The Hobbit","The Lord Of The Rings"
我试过了
let $args := $context//xml/books
let $lines := tokenize($args, ',')
return
string-join(concat("'", $lines, "'"), ",")
不幸的是我得到了这个错误。有人可以帮忙吗?
不允许将超过一项的序列作为 concat() 的第二个参数 ("Harry Potter","The Hobbit","The Lord Of The Rings")
您正在将标记序列的字符串序列化版本与开始和结束引号连接起来。相反,您需要遍历您的标记,并对每个标记应用引号。
string-join(
for $l in $lines
return concat('"', $l, '"'),
",")