Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

Creates an element with the specified name in the output.

Syntax

<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 Qualified Name, the element node is created in the name space currently bound to the prefix unless otherwise overridden by the presence of a namespaceattribute. The value of the nameattribute 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 name space URI of the created element. If the name element contains a Qualified Name, the prefix specified there will be bound to the name space specified in the name space attribute, possibly resulting in the addition of additional name space declarations when serializing. This value is interpreted as an attribute value template.

use-attribute-sets

A white space-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

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 nameattribute and an optional namespaceattribute. 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 name space clashes, such as XSLT itself.

Examples

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

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

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

Copy Code
<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

Reference

XSLT Elements