Chapter 5 Customizing Generation with GTL
This macro iterates on the part of the input template specified as the first argument to the macro. The template specified inside the block is translated for each part of the input, with parts delimited by a separator pattern.
.foreach_part (input [,"separator-pattern" [,head [,tail]]]) simple-template .next[(separator)]
This macro creates a new scope wherein the local variable CurrentPart is defined to be the i-th part of the input template at iteration i. The Separator local variable contains the following separator.
This macro is particularly useful when you work with naming conventions.
For more information about naming conventions, see "Naming conventions" in the Models chapter of the Core Features Guide.
The following parameters are available:
Parameter | Description |
---|---|
input | Input text over which iteration is performed
Type: Simple template |
separator-pattern | Char and word separators
For example, the pattern " -_,[A-Z]" specifies that each part can be separated by a space, a dash, an underscore, a comma or a character between A and Z (in capital letter). By default, the <separator-pattern> is initialized with the pattern (). If the specified pattern is empty, the pattern is initialized using the default value. A separator <separator> can be concatenated between each part. <head> and <tail> expressions can be added respectively at the bottom or at the end of the generated expression. There are two kinds of separator:
Default: " -_,\t" Type: Text |
head | [optional] Generated before output, if there is one
Type: Text |
tail | [optional] Appended to the output, if there is one
Type: Text |
simple-template | Template to apply to each part.
Type: Complex template |
separator | [optional] Generated between non empty evaluations of <complex-template>
Type: Text |
Examples:
Convert a name into a class code (Java naming convention). In the following example, the variable %Name% is equal to Employee shareholder, and it is converted to EmployeeShareholder:
.foreach_part (%Name%, " _-'") %.FU:CurrentPart% .next
Convert a name into a class attribute code (Java naming convention). In the following example, the variable %Name% is equal to Employee shareholder, and it is converted to EmployeeShareholder:
.set_value(_First, true, new) .foreach_part(%Name%,"' _-'") .if (%_First%) %.L:CurrentPart% .set_value(_First, false, update) .else %.FU:CurrentPart% .endif .next
Copyright (C) 2008. Sybase Inc. All rights reserved. |
![]() |