In one of my previous posts about the OmniMark conversion scheme I explained the different translate types at high level.

I will now demonstrate a simple OmniMark downtranslate example. In this example an XML document is converted to (X)HTML.

OmniMark source code embedded with XML source
process
  do xml-parse
    scan 'The exiting world of OmniMark' ||
         '
First title' || '
Subsection of first title' || 'A paragraph with some text...' || 'A second paragraph with some text...' || '
' || '
' || '
Second title' || 'Text in the second section.' || '
' || '
' output '%c' done element #implied output '%c' element doc output '%n' output '%n' output '%c' output '%n' output '' element title when parent is doc output '<%q>%c%n' output '' element title when parent is section do when parent of parent is doc output '

%c

%n' else when parent of parent is section output '

%c

%n' done element par output '

%c

%n'
The resulting output


The exiting world of OmniMark

First title

Subsection of first title

A paragraph with some text...

A second paragraph with some text...

Second title

Text in the second section.

Explaining the source code

You can see that the syntax of the language is very declarative for itself.

The

do xml-parse scan ... done

block is the part where the XML input source is the input data for the parser. The XML source is not loaded as a whole into memory but it streams like a water flow through the parser. While it streams, events occur and the corresponding element rules are fired.

The order in which these element rules are written is not important, they are only fired when the corresponding event occurs.

%c explained

The % character is an escape character,

%c

is the parse continuation operator so the XML source continues to flow and element rules are fired, less or more comparable with the XSLT

&lt;xsl:apply-templates/&gt;

element.

An other escape sequence is

%n

which represents a newline.

%q

is for the name of the current element.

No nested rules, but nested execution of the rules

The first rule which is fired when the input data flows and the <doc> start tag is encountered is the

element doc

rule on line 20. Because

%c

is used on line 25, the XML stream continues to flow and other element rules will be fired. At the end of the stream when the end tag </doc> is encountered, line 26 and 27 will be the last lines that will be executed.

The default element rule

element #implied

Every element must have a corresponding element rule, if not an error will raise.

The section element has no specific rule, so the

element #implied

is fired. In this specific case the rule says “go on with the stream, no specific output”.

Rating 3.00 out of 5
[?]