Partager via


xsl:element Element

A version of this page is also available for

Windows Embedded CE 6.0 R3

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

Number of occurrences

Unlimited

Parent elements

xsl:copy, 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:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, 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 name space 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

Reference

XSLT Elements