Creates an element with the specified name in the output.
<xsl:element name = "element-name" namespace = "uri-reference" use-attribute-sets = QName </xsl:element>
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 |
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.
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>
Generating More Sophisticated Output