Construct an XML element.
An ElementConstructor
constructs an XML element. It consists
of a QName, that is used in start and end tag, an attribute list that may be
empty, and the actual content of the element that may be empty as well.
You can construct elements in the following ways:
Using Direct Constructors
If name, attributes and content of the element are constants, the
element is constructed as is:
<section type="overview" lang="en"> <para>CVS marks version conflicts by displaying the conflicting areas from both files and delimits this section using <![CDATA[<<<<<<]]> at the beginning and <![CDATA[>>>>>>]]> at the end.</para> </section>
This constructs the element section
with an
attribute list containing the attributes type
and lang
. In terms of the data model, it
constructs an element node and two attribute nodes.
The content is another element para
which in turn is
constructed by an element constructor. That element has no attribute, but
character data and two enclosed CDATA sections. For
para
the constructor creates an element node and a
non-empty text node.
Using Enclosed Expressions
Enclosed expressions are delimited by braces. They are evaluated and
replaced with the resulting value:
for $a in input()/bib/book return <book> <title>{ $a/title }</title> <notitle>$a/title</notitle> </book>
The expression { $a/title }
is evaluated and for each
tuple returned by the for
clause it is replaced with the contents
of the respective title
. The content of the
notitle
element is a constant string literal and
will be constructed as is.
Using Computed Constructors
Tamino also supports computed constructors for elements and attributes.
They are introduced with either the keyword element
or the keyword
attribute
followed by the name of the node, which must be a string
literal, and an enclosed expression that evaluates to the content of the
respective node. Computed constructors may be nested and several constructors
are separated by commas:
element section { attribute type { "overview" }, attribute lang { "en" }, element para { "This section deals with element constructors." } }
This constructs the same element as in the first example. Similarly, you can construct the second example:
for $a in input()/bib/book return element book { element title { $a/title }, element notitle { "$a/title" } }
This form of attribute constructor in the first expression is needed in
the context of update expressions. See the section
Performing Update Operations
in the XQuery 4 User Guide for information about updating
attribute nodes with the help of a
ComputedAttributeConstructor
.
The following construct(s) refer to this construct:
This construct is also related to the following construct(s):
AttributeList
|