Model Templates : Properties : Properties Segment Section : Using Nested FOR Loops to Extract Attribute Names and Values

Using Nested FOR Loops to Extract Attribute Names and Values

The next part of the template involves the use of nested FOR/LOOP constructs for extracting and writing the data-item’s attribute name and value. A data-item’s attributes and their values are recorded in special fields in the data-item form. The information in these fields is textual and can involve any features of the data-item that you want. The field enables you to record a list of attributes and values.

Recall that FOR loops are used to iterate on items of a list. In this template, the list of data-item attributes is represented by a LIST OF STRING variable, attr_list. The template executes a sequence of statements for each attribute (represented by the string variable attr) contained in the list.

These statements involve extracting and writing the corresponding attribute values for each attribute listed in the attribute name field. First, the template uses uses a database extraction function to assign values to a LIST OF STRING variable, attr_val_list. This variable represents the list of attribute values recorded in the attribute value field for a particular attribute name, represented by the variable attr.

This template assumes that more than one value can be recorded for each attribute; therefore, another FOR/LOOP construct is used to write the information for each value (represented by the variable attr_val) in the list.

You want to write attribute name and value as a paired set, with the attribute value written next to the attribute name. The template uses the number 20 in the WRITE statement to indent the second output field 20 characters. Note that for “:” to appear after the attribute name, the template uses a concatenation of two strings (attr +’:’).