Convert XML data to CSV string using XQuery
Consider the following XML:
<LIST>
<Name>Jon</Name>
<Name>Dan</Name>
<Name>Bill</Name>
<Name>Jack</Name>
</LIST>
I need the output as a string as CSV, for example Jon,Dan,Bill,Jack
using XQuery.
I did it using FLWOR and expressions and normalize-space
then replaced the spaces with commas. However, I believe there should be a better way to do this in XQuery.
+3
Ranjith Reddy
source
to share
1 answer
You can use a function string-join
for this:
string-join(//Name/text(),",")
fn: string-join ($ arg1 as xs: string *, $ arg2 as xs: string) as xs: string
Returns the string xs: created by concatenating the members of the $ arg1 sequence using $ arg2 as the delimiter.
https://www.w3.org/TR/xpath-functions/#func-string-join
+6
zeppelin
source
to share