Enclosed expressions in constructors

Enclosed expressions are used in constructors to provide computed values for element and attribute content. These expressions are evaluated and replaced by their value when the constructor is processed. Enclosed expressions are enclosed in curly braces ({}) to distinguish them from literal text.

Enclosed expressions can be used in the following constructors to provide computed values:
  • Direct element constructors:
    • An attribute value in the start tag of a direct element constructor can include an enclosed expression.
    • The content of a direct element constructor can include an enclosed expression that computes both the content and the attributes of the constructed node.
  • Computed constructors:
    • An enclosed expression can be used to generate the content of the node.
For example, the following direct element constructor includes an enclosed expression:
<example>
  <p> Here is a query. </p>
  <eg> $b/title </eg>
  <p> Here is the result of the query. </p>
  <eg>{ $b/title }</eg>
</example>
When this constructor is evaluated, it might produce the following result (whitespace is added to this example to improve readability):
<example>
  <p> Here is a query. </p>
  <eg> $b/title </eg>
  <p> Here is the result of the query. </p>
  <eg><title>Harold and the Purple Crayon</title></eg>
</example>
Tip: To use a curly brace as an ordinary character within the content of an element or attribute, you can either include a pair of identical curly braces or use character references. For example, you can use the pair {{ to represent the character {. Likewise, you can use the pair }} to represent }. Alternatively, you can use the character references &#x7b; and &#x7d; to denote curly brace characters. A single left curly brace ({) is interpreted as the beginning delimiter for an enclosed expression. A single right curly brace (}) without a matching left curly brace is an error.