<c:element
name = { qname }
namespace? = { uri }
use-attribute-sets? = eqname* >
<!-- Content: sequence-constructor -->
</c:element>
Creates an element node.
- Category
- instruction
- Permitted parent elements
- Any XCST element whose content model is sequence-constructor
- Any literal result element
Attributes
name |
The name of the element. |
namespace |
The namespace of the element. |
use-attribute-sets |
Specifies attribute sets to use on the element. |
In addition to the attributes in the preceding table, there are a number of standard attributes that may appear on any XCST element.
Example
<c:element name='{(url != null ? "a" : "span")}'>
...
</c:element>
Example: Creating an XElement
<c:variable name='foo'>
<c:element name='foo'>
<c:attribute name='bar'>123</c:attribute>
<c:text>baz</c:text>
</c:element>
</c:variable>
<c:assert test='foo is XElement'/>
<c:assert test='"foo" == foo.Name.LocalName'/>
<c:assert test='"123" == foo.Attribute("bar").Value'/>
<c:assert test='"baz" == foo.Value'/>
You can also create an XElement using a literal result element.
Differences with xsl:element
When the ‘namespace’ attribute is omitted and the ‘name’ attribute specifies an un-prefixed qualified name, the namespace for c:element
is resolved at run-time. This allows you to write code that works the same way for any namespace. For example:
<c:template name='html'>
<html>
<body>
<c:call-template name='table'/>
</body>
</html>
</c:template>
<c:template name='xhtml'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<body>
<c:call-template name='table'/>
</body>
</html>
</c:template>
<c:template name='table'>
<c:element name='table'>
...
</c:element>
</c:template>
When the html
template is called, the table
element will be in the null namespace. When the xhtml
template is called, the table
element will be in the http://www.w3.org/1999/xhtml
namespace.
Being unaffected by the default namespace also allows you to use c:element
when writing XCST code without using a prefix.
Error Conditions
It is a compilation error if the required item type of the containing sequence constructor is not one of, or a super class of, Object, XElement or XmlElement.