Chris Wallace
Chris Wallace

Reputation: 515

How to Include spaces in XQuery string-join()

let $text :=
<a>
  <b>f</b>
  <b>a</b>
  <b> </b>
  <b>l</b>
</a>

return 
  string-join($text/b,"")

yields "fal" rather than "fa l"

Upvotes: 1

Views: 2129

Answers (1)

Gunther
Gunther

Reputation: 5256

string-join will include spaces, but the constructor may have dropped them according to the effective setting of boundary space.

The result that you are seeing would be correct for a setting of "strip", where you effectively are constructing a node without any boundary whitespace, i.e.:

<a><b>f</b><b>a</b><b/><b>l</b></a>

You can enforce keeping boundary space by adding this declaration to the query prolog:

declare boundary-space preserve;

Upvotes: 4

Related Questions