Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Higher order functions such as this are a powerful programming technique, particularly when handling complex data structures.
See Also
xsl:attribute
The
Changes in 2.0
The content of the attribute can be specified using a
select
attribute, as an alternative to using a sequence constructor. The
separator
attribute can be used to format the attribute value when the content is supplied as a sequence.
With a schema-aware XSLT processor, the
type
and
validation
attributes can be used to control the type annotation given to the new attribute node.
Format
name = { qname }
namespace? = { uri-reference }
select? = expression
separator? = { string }
validation? = “strict” | “lax” | “preserve” | “strip”
type? = qname>
Position
sequence constructor
, or within an
Attributes
Name | Value | Meaning |
name mandatory | Attribute value template returning a lexical QName | The name of the attribute node to be generated |
namespace optional | Attribute value template returning a URI | The namespace URI of the generated attribute node |
select optional | XPath Expression | Provides the value of the attribute |
separator optional | Attribute value template returning a string | Separator string to be inserted between items when the value is a sequence |
validation optional | strict , lax , preserve , or skip | Indicates whether and how the attribute should be subjected to schema validation |
type optional | Lexical QName | Identifies a type declaration (either a built-in type, or a user-defined type imported from a schema) against which the new element is to be validated |
The
type
and
validation
attributes are mutually exclusive: if one is present, the other must be absent.
Content
A sequence constructor, unless the
select
attribute is present, in which case the content must be empty.
Effect
The effect of this instruction is to create a new attribute node and to return this node as the result of the instruction. In the usual case where the sequence constructor containing the
name
and
namespace
attributes. The way in which these attributes are used is described below in the section
The Name of the Attribute
.
The value of the new attribute node may be established either using the
select
attribute or using the sequence constructor contained in the
select
attribute is present, the
The Value of the Attribute
.
When a schema-aware XSLT processor is used, the new attribute may be validated to ensure that it conforms to a type defined in a schema. This process results in the new attribute node having a type annotation. The type annotation affects the behavior of subsequent operations on this attribute node even though it is not visible when the result tree is serialized as raw XML. The validation and annotation of the new attribute node are controlled using the
type
and
validation
attributes. This is described in the section
Validating and Annotating the Attribute
.
The Name of the Attribute
The name of an attribute node has three parts: the prefix, the local name, and the namespace URI. These are controlled using the
name
and the
namespace
attributes.
Both the
name
and the
namespace
attributes may be given as attribute value templates; that is, they may contain expressions nested within curly braces. One of the main reasons for using the
Literal Result Elements
in Chapter 3, page 112) is that
The result of expanding the
name
attribute value template must be a lexical
QName
; that is, a valid XML name with an optional namespace prefix, for example,
code
or
xsi:type
. If there is a prefix, it must correspond to a namespace declaration that is in scope at this point in the stylesheet, unless there is also a
namespace
attribute, in which case it is taken as referring to that namespace.