Well, I had hoped I could push looking it up to you.
But
http://www.w3.org/TR/xquery/#id-content says:
The part of a direct element constructor between the start tag
and the end tag is called the
content of the element
constructor. This content may consist of text characters (parsed as
ElementContentChar),
nested direct constructors,
CdataSections, character and
predefined entity references,
and
expressions enclosed in curly braces.So, { } are legal inside direct element constructors and are interpreted. This means that, oddly enough, the value returned by BaseX actually can't be used in a direct element constructor.
In my opinion, BaseX shouldn't return XML in a form that can't be used as a direct element constructor. (Note that you don't escape the CDATA, even though it contains { }.