specified attributes

built-in shelf

Purpose

The keyword specified attributes represents the set of all specified attributes of an element as a shelf. The name of the attribute is used as the key, and the value of the attribute is stored in the shelf item value. The type of the shelf and all its items is specified-attribute, which can always be converted to a string as well.

To reference the attributes of a specific element, the element can be qualified in all of the same ways as attribute references. The specified attributes shelf doesn't 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 specified attributes shelf are indexed in the order in which the attributes occur in the element's start tag, as opposed to their declaration order provided by the attributes shelf.

In the following output action, for example, the value of the first attribute specified in the start tag is output, no matter where it appears in the order of declarations. This action is an error if no attributes are specified in the start tag, even if there are declared attributes and they all have default values.

     output specified attributes[1]

Applying the has key test to the attributes shelf determines whether an element has a specified attribute. If it does, the attribute and the shelf item necessarily has a value. Every key present in the specified attributes shelf is always also present in the attributes shelf.

The number of attributes specified for an element can be determined by applying number of to specified attributes.

The following example shows how the of parent element qualifier can be used to refer to a specified attribute of the parent element, instead of the currently opened element:

     output specified attribute "this-one" of parent

Using the specified attributes shelf for normalization

This code fragment illustrates the utility of the specified attributes shelf. When used, it will output normalized start tags and end tags around the content of the current element, with all specified attribute values included.

This example can be used as a simple but complete OmniMark program that normalizes an SGML document. In practice, such a program will also need to:

  • print the default attribute values if desired
  • deal with some or all of the processing instructions, internal and external data entities, external text entities, SGML comments, marked sections, and white space
  • protect data characters when they might be interpreted as markup
  • add line breaks where it is safe to do so

  element #implied
     output "<%q"
     repeat over specified attributes as this-attribute
        output " "
            || key of attribute this-attribute
            || "=%"%v(this-attribute)%""
     again
     output ">" _
            "%c"
     output "</%q>" unless content is (empty | conref)