Xcerpt Tutorial - Chapter 1 (Hello World)
Hello World
It is a tradition for programming tutorials to begin with a "Hello
World" example. The output of the following Xcerpt program is <p>Hello
World</p>:
GOAL
p { "Hello World" }
END
On this simple example, one can observe the following properties:
-
Xcerpt uses a non-XML syntax. The rationale behind not using
XML syntax is that the XML syntax does not support some special
properties (explained below) and to emphasise that Xcerpt is not
explicitly limited to XML data.
-
An Xcerpt program consists of at least one "Goal". Goals
special kinds of "Rules" and are the equivalent of the "main"
function in many programming languages: If an Xcerpt program is
executed, evaluation starts at the goals and the goals determine the
output.
A goal has the following structure:
GOAL
<construct part>
FROM
<query part>
END
In a goal (and a rule), "cons" is wrapped around a term serving as
construction pattern, and "query" is wrapped around a query
specification (explained below). A "cons" part may be associated
with an output resource, specifying where to write the results. If no
output resource is provided, output is written to standard output. The
following modified "Hello World"-example writes the document <p>Hello
World</p> to the file "hello.html":
GOAL
out {
resource { "file:hello.html", "xml" },
p { "Hello World" }
}
END
Summary of Chapter 1
Sebastian Schaffert
Last modified: Wed Mar 12 11:55:08 CET 2003