Java Reference
In-Depth Information
14.1.2 DEFINE
Although an
.xpt
file is called a template file, in Xpand, the content of a
«DEFINE»
block is considered the template. This topic uses the word
template
to reference both. A
«DEFINE»
block represents a fragment that is expanded in
the context of executing the template. A
«DEFINE»
block has a name and
optional list of parameters, along with a
FOR
clause that specifies the applicable
element of the metamodel. An
«ENDDEFINE»
tag terminates the
«DEFINE»
block. This is the general syntax for a
«DEFINE»
statement:
«
DEFINE
templateName (parameterList)
FOR
MetaClass»
. . .
«ENDDEFINE»
This is a simplistic template that describes
«DEFINE»
and other Xpand ele-
ments. It takes a mindmap instance and produces a Comma-Separated Values
(CSV) file.
«
IMPORT
mindmap»
«
DEFINE
Main
FOR
Map»
«
FILE
title + ".csv"-»
«
FOREACH
elements.typeSelect(Topic)
AS
topic-»
«topic.name»,«topic.start»,«topic.end»
«
ENDFOREACH
»
«
ENDFILE
»
«ENDDEFINE»
The
«DEFINE»
statement includes the name
Main
and indicates that the
mindmap model's Map class is the metamodel element used in the definition.
This example passes no parameters. Within the body of the
«DEFINE»
block,
output text is placed, along with other Xpand statements. I explain the contents
of the example in detail shortly, but it's not hard to see that an output file is cre-
ated and will contain a series of Topic attributes separated by commas. Consider
this sample output:
A Topic,Tue Nov 20 10:16:00 EST 2007,Fri Nov 23 12:46:20 EST 2007
A Subtopic,Wed Jun 20 00:00:00 EDT 2007,Sat Aug 09 00:00:00 EDT 2008
Another Topic,Sun Sep 09 00:00:00 EDT 2007,Wed Dec 12 00:00:00 EST 2007
Another Subtopic,Sat Dec 01 00:00:00 EST 2007,
Tue Jan 01 00:00:00 EST 2008
A SubSubtopic,Mon Oct 22 00:00:00 EDT 2007,Sat Dec 08 00:00:00 EST 2007
Search WWH ::
Custom Search