<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="xsl-elements" page="element" subpage=""/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: xsl:element</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: xsl:element"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>xsl:element</h1> <p>The <code>xsl:element</code> instruction is used to create an output element whose name might be calculated at run-time.</p> <p>The element has a mandatory attribute, <code>name</code>, which is the name of the generated element. The name attribute is an <i>attribute value template</i>, so it may contain string expressions inside curly braces.</p> <p>The attributes of the generated element are defined by subsequent <code>xsl:attribute</code> elements. The content of the generated element is whatever is generated between the <code><xsl:element></code> and <code></xsl:element></code> tags.</p> <p>Additionally, attributes of the generated element can be defined by reference to a named attribute set. The optional use-attribute-sets attribute contains a white-space-separated list of attribute set names. They are applied in the order given: if the same attribute is generated more than once, the later value always takes precedence.</p> <p>For example, the following code creates a <FONT> element with several attributes:</p> <div class="codeblock" style="border: solid thin; background-color: #B1CCC7; padding: 2px"> <pre> <code><xsl:element name="FONT"> <xsl:attribute name="SIZE">4</xsl:attribute> <xsl:attribute name="FACE">Courier New</xsl:attribute> Some output text </xsl:element></code> </pre> </div> <p>A new attribute <code>type</code> was added in XSLT 2.0. This indicates the data type of the value of the element. The value may be a built-in type defined in XML Schema, for example <code>xs:integer</code> or <code>xs:date</code>, or a user-defined type defined in a schema imported using <code>xsl:import-schema</code>. Type annotations are only accessible if the attribute is added to a temporary tree that specifies <code>type-information="preserve"</code>. The attribute causes the content of the element to be validated against the schema definition of the type, and will cause a fatal dynamic error if validation fails.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="evaluate.xml">Next</a></p> </td> </tr> </table> </body> </html>