I have this xquery for a collection of books, which individually have 1 or more fagfelt(topics) each. When i run my query all the topics are grouped up in one cell of the table (I want this), but they are not easily separated
let $books := (doc("oblig3.xml")/bøker/bok)
for $x in $books
order by $x/tittle
<td>Filosofi Kunnskapsrepresentasjon Kunstig Intelligens Programmering</td>
<td>Filosofi, Kunnskapsrepresentasjon, Kunstig Intelligens, Programmering</td>
When you serialize a sequence to a string in XQuery, the defined behavior is to return a space-delimited list. However, if you want to use a custom delimiter, use
fn:string-join($x/fagfelt, ', ')
From the W3C specification:
Each enclosed expression is converted to a string as follows:
a. Atomization is applied to the value of the enclosed expression, converting it to a sequence of atomic values.
b. If the result of atomization is an empty sequence, the result is the zero-length string. Otherwise, each atomic value in the atomized sequence is cast into a string.
c. The individual strings resulting from the previous step are merged into a single string by concatenating them with a single space character between each pair.