Reputation: 111
How would one write some XQuery to solve the following:
This is what I have currently written:
<friends>
{for $lastname in volunteerDatabase/person/name/lastname
return
concat($lastname/string(), ' +')}
</friends>
This query returns:
<Friends>Geller + Bing + Tribbiani +</Friends>
I would like to return the following where all values are separated by '+':
<Friends>Geller + Bing + Tribbiani</Friends>
Sample Dummy Data:
<?xml version="1.0" encoding="UTF-8" ?>
<volunteerDatabase>
<person age="31" ssn="046187254">
<name>
<firstname>Ross</firstname>
<lastname>Geller</lastname>
</name>
<telephone type="landline">
<number>5534567</number>
</telephone>
<telephone type="mobile">
<number>0851234567</number>
</telephone>
</person>
<person age="29" ssn="355817204">
<name>
<firstname>Chandler</firstname>
<firstname>Muriel</firstname>
<lastname>Bing</lastname>
</name>
<telephone type="mobile">
<number>0869932617</number>
</telephone>
</person>
<person ssn="778123666">
<name>
<firstname>Joseph</firstname>
<firstname>Francis</firstname>
<lastname>Tribbiani</lastname>
</name>
<telephone type="landline">
<number>01628777</number>
</telephone>
</person>
</volunteerDatabase>
Any guidance appreciated.
Upvotes: 1
Views: 556
Reputation: 295403
No need for the FLWOR expression:
<friends>{fn:string-join(volunteerDatabase/person/name/lastname, " + ")}</friends>
...returns, when run with your document as the context item:
<friends>Geller + Bing + Tribbiani</friends>
Upvotes: 3