Attribute tests on items of the "attributes" shelf

All the tests that can usually be applied to attributes can be used with any identification of an attribute, where the attribute is identified by using the attribute's name, using an attribute alias name, or selecting an item of the attributes shelf.

Because all attributes of specified attributes are, by definition, specified, the is specified, is defaulted, and is implied tests do not make much sense when applied to it: is specified always succeeds, and is defaulted and is implied always fail.

For example, the following repeat over loop outputs only those attributes whose values are defaulted or specified (excluding those which are implied or unspecified) and whose values consist entirely of letters. The attributes are output in the order in which they are declared. This is accomplished by testing an attribute identified by an attribute alias name:

  process
     do sgml-parse document scan #main-input
        output "%c"
     done
  
  
  element #implied
     output "<%q"
     repeat over attributes as a
        do when attribute a isnt implied & attribute a matches (letter+ value-end)
           output "%_" || key of attribute a
               || "=%"" || attribute a || "%""
        done
     again
     output ">%n%sc%sn</%q>%sn"

Running this program on the following input

  <!doctype a [
  <!element a - - (b+)>
  <!attlist a     a1 nutoken #implied
                     a2 cdata   "strawberries">   
  
  <!element b - - (c+)>
  <!attlist b     c1 cdata "potato jam"
                     c2 cdata "kiwi">   
  
  <!element c - - (#pcdata)>
  <!attlist c     c1 cdata #implied
                     c2 cdata "apples">   
  ]>
  <a>
     <b>
        <c>Text
        </c>
     </b>
  </a>
        
produces this output:
  <A A2="strawberries">
  <B C2="kiwi">
  <C C2="apples">
  Text
  </C>
  </B>
  </A>
        

Related Topics