SAXONICA |
The xsl:element
instruction is used to create an output element
whose name might be calculated at run-time.
The element has a mandatory attribute, name
, which is the name of the generated element.
The name attribute is an attribute value template, so it may contain string expressions inside
curly braces.
The attributes of the generated element are defined by subsequent xsl:attribute
elements. The
content of the generated element is whatever is generated between the <xsl:element>
and
</xsl:element>
tags.
Additionally, attributes of the generated element can be defined by reference to a named attribute set. The optional use-attribute-sets attribute contains a white-space-separated list of attribute set names. They are applied in the order given: if the same attribute is generated more than once, the later value always takes precedence.
For example, the following code creates a <FONT> element with several attributes:
<xsl:element name="FONT">
<xsl:attribute name="SIZE">4</xsl:attribute>
<xsl:attribute name="FACE">Courier New</xsl:attribute>
Some output text
</xsl:element>
A new attribute type-annotation
is available in XSLT 2.0. This indicates the
data type of the value of the element. In Saxon 7.3, the value must be a built-in type defined
in XML Schema, for example xs:integer
or xs:date
. Type annotations
are only accessible if the attribute is added to a temporary tree that specifies
type-information="preserve"
. The value given to the element must be a string
that conforms to the rules for the data type, as defined in XML Schema. In particular
this means that the element must not have any element children.