This documentation is archived and is not being maintained.

<xsl:element> Element 

Creates an output element with the specified name.

  name = "element-name"  
  namespace = "uri-reference"
  use-attribute-sets = QName


Required. The name of the element to create. If this value is a Qualified Names, the element node is created in the namespace currently bound to the prefix, unless overridden by a namespace attribute. The value of the name attribute is interpreted as an attribute value template — that is, 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.


The namespace URI of the created element. If the name attribute contains a QName, the prefix specified there will be bound to the namespace specified in the namespace attribute. This might require additional namespace declarations when serializing. The namespace value is interpreted as an attribute value template.


A white space separated list of attribute sets, specified as a Qualified Names. Specifying this attribute declares each attribute in each listed attribute set.

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.

The <xsl:element> element is necessary because XSLT elements cannot be used as output elements. This example shows how to output an <xsl:template> element.

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="element.xsl" ?>
   <item>My Item</item>

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="" >

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


This is the formatted output:

My Item

The following is the processor output, with line breaks added for clarity.

<?xml version="1.0"?>
<xsl:template match="cost" 
My Item</xsl:template>