swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
  Related Syntax   Related Concepts  
built-in variable   attributes    


The keyword attributes treats the set of all declared attributes of an element as a shelf. The name of the attribute is used as the key, and the value of the attribute is obtained from the value of the item.

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 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, and one must be defined by the programmer with using or repeat over.

The attributes shelf is indexed as follows:

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 doesn't have a specified (or defaulted) value:

  output attributes[1]

In the following output action, however, 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 declared attribute. Note, however, that just because an attribute is declared, it does not necessarily have a value.

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

The following example shows how the of element element qualifier can be used to refer to an attribute of the currently opened element:

  output attribute this-one of element

The following down-translate program 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)'"
           output " id='%d(id-count)'"
        increment id-count
     output ">%c"
     output "</%q>" when element isnt empty

Using the attribures shelf for normalization

This code fragment illustrates the utility of the 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:

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

  Related Syntax
   using attributes
Related Concepts
   Attribute aliases
   Attribute tests on items of the "attributes" shelf
   Attributes: order of indexing


Generated: August 11, 2000 at 3:06:59 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.