Java Reference
In-Depth Information
«
FOREACH
expression
AS
varName [
ITERATOR
iterName]
[
SEPARATOR
expression]»
. . .
«
ENDFOREACH
»
The
expression
can be any collection element within the current context
or a statement that results in a collection. Within the block, each element in the
collection is accessed using the
varName
you provide. The body of the
FOREACH
block can contain other Xpand statements, including nested
FOREACH
elements.
A special Xpand-provided iterator is accessible by name within the block if the
ITERATOR
is specified. A common use for the
ITERATOR
is to access its counter
for outputting a numerical sequence within the body of the statement. As you
saw earlier, you can declare a
SEPARATOR
and insert it between elements in the
collection. Section 14.1.13, “Type System,” covers the full list of features that an
iterator offers.
To illustrate the use of an
ITERATOR
, consider this
«DEFINE»
block:
«
DEFINE
NumberedCsvFile
FOR
Map»
«
FILE
"numbered-" + title + "-topics.csv"-»
«
FOREACH
elements.typeSelect(Topic)
AS
topic
ITERATOR
i-»
«i.counter0»,«topic.name»,«topic.start»,«topic.end»
«
ENDFOREACH
»
«
ENDFILE
»
«
ENDDEFINE
»
In this case, we're prefixing each line in our output CSV file with an
index obtained by our iterator's
counter0
property. The output looks like the
following.
0,A Topic,Tue Nov 20 10:16:00 EST 2007,Fri Nov 23 12:46:20 EST 2007
1,A Subtopic,Wed Jun 20 00:00:00 EDT 2007,Sat Aug 09 00:00:00 EDT 2008
2,Another Topic,Sun Sep 09 00:00:00 EDT 2007,
Wed Dec 12 00:00:00 EST 2007
3,Another Subtopic,Sat Dec 01 00:00:00 EST 2007,
Tue Jan 01 00:00:00 EST 2008
4,A SubSubtopic,Mon Oct 22 00:00:00 EDT 2007,
Sat Dec 08 00:00:00 EST 2007
14.1.6 EXTENSION
Xpand supports the extension of the underlying metamodel through the
«EXTENSION»
statement. Declaring an
«EXTENSION»
import in a template
Search WWH ::
Custom Search