Xmlt user guide


Table of contents


Introduction

Xmlt (Xmlt Merges Layout and Text) uses the DocumentTemplate module from Zope to merge a layout (described in a dtml-file) and the text (found in xmlt-files). The generated HTML document is written to a html-file. The xmlt usage is shown below:
xmlt [-n ns.py..] dtml-file xmlt-files.. html-file

The first argument is a dtml-file describing the layout of the generated document. A dtml-file is a HTML file width some additional dtml semantics. These includes conditional statements and attributes. Check the Zope home page for a more detailed description of this format. The layout file for this document and the layout file in the example directory are examples of such dtml-files.

The last argument is the name of the generated HTML file. Xmlt can not write the result to stdout since it needs the name of the generated HTML file. You can in the layout-file refer to this name in the current attribute. E.g., if the generated file is ex.html, then the current attribute has the value "ex.html".

The rest of the arguments (xmlt-files..) are the contents of the document. This usually includes two files, one with some global settings and one with the actual text. The example in the example directory uses a def.xmlt file for the global settings. The actual contents of the documents are found in the ex.xmlt and fx.xmlt files, respectively.

Optionally you can specify one or more Python name space files (using the -n flag) containing attributes and functions used in the dtml-file (or in the xmlt-files).

Xmlt, examples and some documentation are available from the Python Starship.

The xmlt-files

The xmlt program defines a new file format, the xmlt-files format. This format is closely related the HTML format.

The contents of an xmlt-file

The contents of an xmlt-file is equal to the body part of an HTML file (the part of an HTML file inside the <BODY> and </BODY> tag including the tags). The difference is that some of the comments have a special meaning and the user can add new user defined tags. Below is an example of the contents of a simple xmlt-file (simple.xmlt):
<!-- vtags:comment -->
<!-- toc -->
<!-- tag:mark:<em>::</em> -->

<title>A title</title>

<comment>
This is an example document.
</comment>

<body>

<h2>This is a sub-title</h2>
This is the text in the document.

<h2>This is another sub-title</h2>
This is <mark>more<mark> text in the document.

</body>

<!-- hhmts start -->
Last modified: Thu Feb  3 09:53:07 CET 2000
<!-- hhmts end -->
Xmlt will work with a valid HTML file too. The stuff outside the body part of an HTML file are ignored (except the title, user defined values [vtags] and some of the comments).

Attributes and flags

An xmlt-file can contain attributes and flags. These attributes and flags are used to adjust the layout generated for this specific document. An example is a flag english used to specify that the layout of this document should be adjusted for the English language (language specific parts are presented in English). This flag is set in the beginning of the xmlt-file with the following line:
<!-- english -->
An attribute is given a value. Most attributes are interpreted as a text string. An attribute is usually used to insert document specific text in the layout description. An attribute author is given the value "A Name" with the following line:
<!-- author:A Name -->
An attribute and a flag can be used inside the xmlt-file too. This is not the common use, but it is sometimes convenient. The syntax is equal to the syntax used in the layout file (see below).

Special xmlt attributes and flags

Some attributes and flags have a special meaning for xmlt. The simple xmlt-file example above introduces three of them, the vtags attribute, the toc flag and the tag attribute. Each flag and attributed with a special meaning are given a short description below.

Xmlt configuration flags and attributes

The following configuration flags and attributes for the xmlt program can be set by the user in the xmlt-file:
toc
Generate a table of contents of the document. This flag will trigger the generation of a table of contents for the document. The generated table of contents will be available in the toc attribute (the flag became an attribute). The toc attribute is usually used in the layout file.

vtags
List of user defined value tags. The simple xmlt example above listed two user defined value tags in this attribute: comment and about. These tags are then later used once in the xmlt-file. The result is that an attribute with the name of the tag is given the value (contents) of the tag. These attributes are then usually used in the layout file.

tag
List user defined tags. This is used to define new tags that can be used more than one time in a document. The vtags is a list of tags used to insert a value (text) in a generated attribute. A value tag in this list can only be used once. However, tag are used to create user defined tags. The simple xmlt file above creates one such tag, the mark tag. Use one such tag creation expression for each tag you create.

clevel
Number of levels in the table of contents

Xmlt generated flags and attributes

Xmlt also generates some flags and attributes that can be used in the layout file (and in the xmlt files):
toc
Xmlt generates a table of contents in this attribute if the toc flag is set.

title
The title of the document is available in this attribute.

body
The contents (body) of the document is available in this attribute.

user defined value tags
The value (text) between user defined value tags (vtags) are available in and attribute with the name of the tag. The simple.xmlt example above will generate the following attributes: comment and about.

current
This attribute contains the name of the generated HTML file. The attribute has the value xmlt.html in this user guide.

rcsKeyword
The RCS set of attributes are fetched from the RCS keywords found in the xmlt files. <!-- $Date: 2000/07/25 11:04:29 $ --> and <!-- $Author: aa $ --> are examples of such keywords in an xmlt file. Read your RCS (or CVS) documentation for more details. The value of the RCS attribute rcsDate in this user guide is "2000/07/25 11:04:29".

timestamp
This attribute contains a time-stamp for the last time document was modified. This value is fetched from the "Last modified:" expression between <!-- hhmts start --> and <!-- hhmts end --> comments (se the simple xmlt file above). The actual value is in my case inserted by my editor when I save the xmlt file.

xmlt_version
The version of the xmlt program that generated this document. The value in this document is "1.23"

xmlt_date
The date of the xmlt program that generated this document. The value in this document is "2002/04/11 12:42:07"

xmlt_msg
A standard message that can be used in a document to show that this document was created with xmlt. This standard message is used at the end of this document.

Xmlt files usage

The common use of xmlt files is to use one (or more) for global setting and one for local settings and the actual conetents of the document. The def.xmlt in the example directory defines the global settings for the two different documents with their contents and local settings in ex.xmlt and fx.xmlt. The simple.xmlt file (see above) is an example with only one xmlt file. All settings and the contents are located in a single file. This user guide is another example of a document using only one xmlt file. However, xmlt are meant to be used in the genration of a lot of HTML files with a similar layout that can be changed in a single layout file. In these cases are the use of xmlt files with global settings very usefull. Such global settings often includes the user defined tags, commonly used graphics (logos) and other settings used in many documents.

The layout file

The layout file is an ordinary HTML file where the different parts of the document are glued together. The file contains special comments that are replaced by the actual contents. Below is an example of a simple layout file simple.dtml:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE><dtml-var title></TITLE>
</HEAD>
<BODY>

<H1><dtml-var title></H1>

<dtml-if comment>
<P><dtml-var comment>
</dtml-if>

<dtml-if toc>
<H2>Table of contents</H2>
<dtml-var toc>
</dtml-if>

<P><dtml-var body>

<dtml-if about>
<P><EM><dtml-var about></EM>
<dtml-else>
<P><EM><dtml-var name="xmlt_msg"></EM>
</dtml-if>

<P><EM>Last updated: <dtml-var timestamp></EM>

</BODY>
</HTML>
The use of this simple layout together with the simple xmlt file above generates the following HTML file: simple.html.


This document has been created using xmlt version 1.23 (2002/04/11 12:42:07), © Anders Andersen 1999-2002
Last updated: 2000/07/25 11:04:29 (aa)