built-in shelf
attributes (of element-expression)?
The built-in shelf attributes
represents the set of all declared attributes of an element. The
name of the attribute is used as the key, and the value of the attribute is stored in the value of the shelf
item. The type of the attributes
shelf is declared-attribute
, while each of its items is either
of the specified-attribute
or the implied-attribute
type. The items whose type is specified-attribute
will also be present in the specified attributes
shelf.
To reference the attributes of a specific element, the element can be qualified in all of the same ways as
attribute
references. The attributes
shelf does not really have a name, so aliases are used
to identify items in the set of attributes. There is no default current item in a set of attributes.
The items of the attributes
shelf are indexed in the order in which the attributes are declared,
instead of the order in which the attributes occur in the element's start tag. To access the attributes in the
same order they appear in the start tag, use the specified attributes
shelf instead.
For example, the following output action gives the value of the first attribute declared for the current
element, no matter what its name or where its value is specified in a start tag. The following is an error if
there are no attributes declared for the currently opened element, or if the first declared attribute does not
have a specified (or defaulted) value:
output attributes[1]
Applying the has key
test to the attributes
shelf determines whether an element has
a declared attribute. Note, however, that just because an attribute is declared, it does not necessarily have a
value. The set of keys present in the attributes
shelf is a superset of the set of keys of the
specified attributes
shelf, whose all items have values.
The number of attributes declared for an element can be determined by applying number of
to
attributes
.
The following example shows how the of parent
element qualifier can be used to refer to an
attribute of the parent element, instead of the currently opened element:
output attributes of parent {"a"}
The attributes of
phrase can also be applied to an element-declaration
value, in which case it
return a shelf of type attribute-declaration
.
The following rule uses the attributes shelf to add id
attributes to elements that can have
them:
global integer id-count element #implied output "<%q" do when attributes has key "id" do when attribute id is cdata output " id=%"%q/%d(id-count)%"" else output " id=%"%d(id-count)%"" done increment id-count done output ">%c" output "</%q>" unless content is empty