XQuery/Displaying Lists

Motivation
You have a list of items in an XML structure and you want to display a comma separated list of the values in an output string.

Method
XQuery provides the "string-join" function that will take a sequence of items and a separator string and create and output string with the separator between each of the items. The format of the function is: where nodeset is a list of nodes and separator the string that you would like to separate the values with.

Output
= Create a CSV file from XML = We will use two "string-join" functions, one for all rows and one for each row. We will create one large string and then use the "response:stream" function to return the results.

Which returns: Row1 Col1,Row1 Col2,Row1 Col3,Row1 Col4 Row2 Col1,Row2 Col2,Row2 Col3,Row2 Col4 Row3 Col1,Row3 Col2,Row3 Col3,Row3 Col4 Row4 Col1,Row4 Col2,Row4 Col3,Row4 Col4

= Discussion = The "string-join" function takes two arguments, the first is the sequence of strings to be joined and the second is the separator.