Consider the following XML:
<LIST>
<Name>Jon</Name>
<Name>Dan</Name>
<Name>Bill</Name>
<Name>Jack</Name>
</LIST>
I need output as a string as a CSV like Jon,Dan,Bill,Jack using XQuery.
I have done it using FLWOR expressions and normalize-space and then replacing the spaces with commas. However, I believe there should be a better way to do it in XQuery.
You can use string-join function to do this:
string-join(//Name/text(),",")
fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string
Returns a xs:string created by concatenating the members of the $arg1 sequence using $arg2 as a separator.
https://www.w3.org/TR/xpath-functions/#func-string-join
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With