swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Syntax   Related Concepts  
built-in variable  

attributes

 
 

Purpose

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.

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:

  down-translate
  
  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>" when element isnt empty

Using the attributes 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)%""
     again
     output ">" _
            "%c"
     output "</%q>" when content isnt (empty | conref)

  Related Syntax
 
Related Concepts
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:51:21 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.