Microsoft XML SDK 2.6 - XSLT Reference

xsl:element Element

Creates an element with the specified name in the output.

<xsl:element
  name = "element-name"  
  namespace = "uri-reference"
  use-attribute-sets = QName
</xsl:element>

Attributes

name
Required. Name of the element to create. If this value is a Qname, the element node is created in the namespace currently bound to the prefix unless otherwise overridden by the presence of a namespace attribute. The value of the name attribute is interpreted as an attribute value template (expressions in curly braces are evaluated and converted to strings as in <xsl:value-of>). This allows the name of the element to be calculated or obtained from the source XML.
namespace
The namespace URI of the created element. If the name element contains a Qname, the prefix specified there will be bound to the namespace specified in the namespace attribute, possibly resulting in the addition of additional namespace declarations when serializing. This value is interpreted as an attribute value template.
use-attribute-sets
A whitespace-separated list of attribute sets specified as a qualified name. Specifying a use-attribute-sets attribute is equivalent to adding <xsl:attribute> elements for each of the attributes in each of the named attribute sets to the beginning of the content of the element with the use-attribute-sets attribute, in the same order in which the names of the attribute sets are specified in the use-attribute-sets attribute. It is an error if use of use-attribute-sets attributes on <xsl:attribute-set> elements causes an attribute set to directly or indirectly use itself.

Element Information

Number of occurrences Unlimited
Parent elements xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements
Child elements xsl:apply-templates, xsl:attribute, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

Remarks

The <xsl:element> element allows an element to be created with a computed name. The name of the element to be created is specified by a required name attribute and an optional namespace attribute. The content of the <xsl:element> element is a template for the attributes and children of the created element.

This element provides an escaping mechanism for creating elements with namespace clashes, such as XSLT itself.

Examples

This example shows a template that generates this element in the output:

<xsl:template match="cost" xml:space="preserve">

The <xsl:element> element is necessary because XSLT elements cannot be used as output elements.

<xsl:template match="item">
  <xsl:element name="xsl:template">
    <xsl:attribute name="match">cost</xsl:attribute>
    <xsl:attribute name="xml:space">preserve</xsl:attribute>
    <xsl:apply-templates/>
  </xsl:element>

</xsl:template>

See Also

Generating More Sophisticated Output