html - Separating same kind of element by a comma -
i have xquery collection of books, individually have 1 or more fagfelt(topics) each. when run query topics grouped in 1 cell of table (i want this), not separated
let $books := (doc("oblig3.xml")/bøker/bok) return <html> <head> </head> <body> <table border="1"> <tr>fagfelt</tr><hr/> <tr><td><b>bok title</b></td> <td><b>forfatter</b></td> <td colspan="3"><b>fagfelt</b></td> </tr> { $x in $books order $x/tittle return <tr> <td>{data($x/tittle)}</td> <td>{data($x/forfatter)}</td> <td>{data($x/fagfelt)}</td> </tr> } </table> </body> </html>
example of return -
<td>filosofi kunnskapsrepresentasjon kunstig intelligens programmering</td>
which 4 topics in one, not easy read. how can separate these , make more like
<td>filosofi, kunnskapsrepresentasjon, kunstig intelligens, programmering</td>
preferably within same cell, have tried listing them with
{data($x/fagfelt[1...4]/text())},
and doing separation manually, leaves lot of commas @ end of books 1 topic.
when serialize sequence string in xquery, defined behavior return space-delimited list. however, if want use custom delimiter, use fn:string-join()
:
fn:string-join($x/fagfelt, ', ')
from w3c specification:
each enclosed expression converted string follows:
a. atomization applied value of enclosed expression, converting sequence of atomic values.
b. if result of atomization empty sequence, result zero-length string. otherwise, each atomic value in atomized sequence cast string.
c. individual strings resulting previous step merged single string concatenating them single space character between each pair.
Comments
Post a Comment