Prev | Next |
List Macro
If you need to loop or iterate through a set of Objects that are contained within or are under the current object, you can do so using the %list macro. This macro performs an iterative pass on all the objects in the scope of the current template, and calls another template to process each one.
The basic structure is:
%list=<TemplateName> @separator=<string> @indent=<string> (<conditions>) %
where <string> is a double-quoted literal string and <TemplateName> can be one of these template names:
- Attribute
- AttributeImpl
- Class
- ClassBase
- ClassImpl
- ClassInitializer
- ClassInterface
- Constraint
- Custom Template (custom templates enable you to define your own templates)
- Effort
- InnerClass
- InnerClassImpl
- LinkedFile
- Metric
- Namespace
- Operation
- OperationImpl
- Parameter
- Problem
- Requirement
- Resource
- Risk
- Scenario
- Test
<conditions> is optional and looks the same as the conditions for 'if' and 'elseIf' statements.
Example
In a Class transform, the Class might contain multiple Attributes; this example calls the Attribute transform and outputs the result of processing the transform for each attribute of the Class in scope. The resultant list separates its items with a single new line and indents them two spaces respectively. If the Class in scope had any stereotyped attributes, they would be generated using the appropriately specialized template.
%list="Attribute" @separator="\n" @indent=" "%
The separator attribute, denoted above by @separator, specifies the space that should be used between the list items, excluding the last item in the list.
The indent attribute, denoted by @indent, specifies the space by which each line in the generated output should be indented.
Special Cases
There are some special cases to consider when using the %list macro:
Learn more