如何编写一些XQuery来解决以下问题:
这就是我目前所写的:
<friends>
{for $lastname in volunteerDatabase/person/name/lastname
return
concat($lastname/string(), ' +')}
</friends>
此查询返回:
<Friends>Geller + Bing + Tribbiani +</Friends>
我想返回以下内容,其中所有值都以'+'分隔:
<Friends>Geller + Bing + Tribbiani</Friends>
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>
任何指导意见。
答案 0 :(得分:3)
不需要FLWOR表达式:
<friends>{fn:string-join(volunteerDatabase/person/name/lastname, " + ")}</friends>
...以文档作为上下文项运行时返回:
<friends>Geller + Bing + Tribbiani</friends>