I am extracting data from an XML file and I need to extract a delimited list of sub-elements. I have the following:
for $record in //record
let $person := $record/person/names
return concat($record/@uid/string()
,",", $record/@category/string()
,",", $person/first_name
,",", $person/last_name
,",", $record/details/citizenships
," ")
The element "citizenships" contains sub-elements called "citizenship" and as the query stands it sticks them all together in one string, e.g. "UKFrance". I need to keep them in one string but separate them, e.g. "UK|France".
Thanks in advance for any help!
fn:string-join($arg1 as xs:string*, $arg2 as xs:string) is what you're looking for here.
In your currently desired usage, that would look something like the following:
Testing outside your document, with:
...returns:
Notably,
("UK", "France")
is a sequence of strings, just as a query returning multiplecitizenship
s would likewise be a sequence (the entries in which will be evaluated for their string value when passed tofn:string-join()
, which is typed as taking a sequence of strings for its first argument).Consider the following (simplified) query:
...and its output: