XQuery: how to properly append , in for loop

sivabudh picture sivabudh · Nov 16, 2009 · Viewed 18k times · Source

So I have xml data like this:

  <PhoneNumber>213-512-7457</PhoneNumber>
  <PhoneNumber>213-512-7465</PhoneNumber>

and with this XQuery:

<PhoneNumberList>
{
  for $phone in $c//PhoneNumber
  let $phoneStr := ""
  return concat($phoneStr, $phone) 
}
</PhoneNumberList>

I get:

<PhoneNumberList>213-512-7457213-512-7465</PhoneNumberList>

But I actually want:

<PhoneNumberList>213-512-7457, 213-512-7465</PhoneNumberList>

Could someone shed some light on how to do this?

Answer

asdf picture asdf · Nov 16, 2009
<PhoneNumberList>
{
    string-join($c//PhoneNumber, ", ")
}
</PhoneNumberList>