RenderObjects templates
Introduction
The template language for RenderObjects can be described as
follows. It is a list of the following kinds of string:
Basic emitting commands
{{ id_d
}}: Emits the id_d of the object under
consideration. Only available in
RenderObjects, not RenderXML.
{{ firstmonad
}}: Emits the first monad of the
object under consideration. This is done in base-10, so that if an
object has a set of objects with first monad "3", then "3" is
emitted (without the quotes). Only available in
RenderObjects, not RenderXML.
{{ lastmonad
}}: Emits the last monad of the
object under consideration. This is done in base-10, so that if an
object has a set of objects with last monad "3", then "3" is
emitted (without the quotes). Only available in
RenderObjects, not RenderXML.
{{ dbname
}}: Emits the database name under
consideration. This is the database name given to the constructor
of the RenderObjects class. Only available in
RenderObjects, not RenderXML.
{{ feature integer
}}: Emits the value of the object's
feature given by the integer's 0-based index into the list
of features in the "get" part of the stylesheet for this object
type. Thus if the "get" part says '"get" : [ "surface", "suffix"
]', and the "start" part says: '"start" : "{{
feature 1 }}"', then the value of the object's
"suffix" feature is emitted. The feature value is escaped (mangled)
according to XML rules, such that less-than becomes "<",
greater-than becomes ">", ampersand becomes "&", and
"double tuote" becomes """. Only available in
RenderObjects, not RenderXML.
{{ featurenomangle
integer }}: Just like the
"feature" counterpart just described, except that no XML mangling
takes place. Only available in RenderObjects, not
RenderXML.
{{ counter string
}}: Emits the contents of the
"counter" within the template execution environment, named by the
given string. A counter is simply an integer which has a name, and
which can be incremented and emitted. It always starts at 0, so the
first time you use this, 0 will be emitted, unless you have used
"inccounter", "deccounter" or "setcounter" first.
{{ counter string format
format-string }}: Emits the
contents of the "counter" within the template execution environment,
named by the first string, formatted using the format-string.
The format-string is currently limited to the following
cases. For example:
Empty No formatting is done on the integer. It is just printed as a base-10 number.
017 I.e., a 0-prefixed integer (e.g., 17).
This makes sure that the number string is at least as long as
the given integer (e.g., 17 characters long), and padded with
'0', ASCII 48=0x32.
17 I.e., a non-0-prefixed integer. Same as 017,
except that the padding charater is a space: ASCII 32=0x20.
Document control commands
{{ setnixing doc
}}: Starts "nixing" the output to the
document, i.e., no strings are emitted at all to the output. Strings
are emitted to variables and lists, however. But variables and lists
are not emitted to the document. This state continues until you use
"setnixing off" or "setnixing all".
{{ setnixing all
}}: Starts "nixing" ALL output to the
document and to lists and variables, i.e., no strings are emitted at
all to the output, lists, or variables. This state continues until
you use "setnixing off" or "setnixing doc".
{{ setnixing off
}}: Stops "nixing" (see "setnixing
doc" and "setnixing all" just above).
Counter manipulation commands
{{ inccounter string
}}: Increments the "counter" within
the template execution environment which is named by the given
string, adding 1. If the counter does not exist when this template
is called, it will be created, and will start at 0. It will then be
incremented to 1.
{{ inccounter string
integer }}: Increments the
"counter" within the template execution environment which is named
by the given string, adding the integer given. If the counter does
not exist when this template is called, it will be created, and will
start at 0. It will then be incremented to the integer given.
{{ inccounter string var
string }}: Increments the
"counter" within the template execution environment which is named
by the given string, adding the integer value contained in the
variable named by the string after "var". If the counter does not
exist when this template is called, it will be created, and will
start at 0. It will then be incremented to the integer given in the
variable.
{{ deccounter string
}}: Decrements the "counter" within
the template execution environment which is named by the given
string, subtracting 1. If the counter does not exist when this template
is called, it will be created, and will start at 0. It will then be
decremented to -1.
{{ deccounter string
integer }}: Decrements the
"counter" within the template execution environment which is named
by the given string, subtracting the integer given. If the counter does
not exist when this template is called, it will be created, and will
start at 0. It will then be decremented to the integer given.
{{ deccounter string var
string }}: Decrements the
"counter" within the template execution environment which is named
by the given string, subtracting the integer value contained in the
variable named by the string after "var". If the counter does not
exist when this template is called, it will be created, and will
start at 0. It will then be decremented to the integer given in the
variable.
{{ setcounter string
integer }}: Sets the
"counter" within the template execution environment which is named
by the given string, setting it to the integer given. If the counter
does not exist when this template is called, it will be created, and
will be set to the integer given.
{{ setcounter string var
string }}: Sets the
"counter" within the template execution environment which is named
by the first string, setting it to the integer value obtained from
base-10 decoding the variable named in the second string. If the
counter does not exist when this template is called, it will be
created, and will be set to the integer given.
Variable manipulation commands
{{ setvar
variable-name-as-string new-value-as-string
}}: Sets the string contents of a
variable with the name given to the value given. If the variable
does not exist, it is created.
{{ setvar
variable-name-as-string }}
variable contents... {{ setvarend
}}: Sets the string contents of a
variable with the name given. If the variable does not exist, it is
created. The contents of the variable are set to whatever appears
until setvarend is met. This may include other
templates, but may not include listappendbegin ... listappendend,
nor may it include setvar. The setvarend template need not be in the
same template string as the setvar template, i.e., the first
setvarend met during execution will end the current (and only)
setvar.
{{ emitvar
variable-name-as-string }}:
Emits the contents of the variable with the name given. If the
variable does not exist, it is initialized to be the empty
string.
List manipulation commands
{{ listappendbegin
string }} list contents...
{{ listappendend }}
: Appends the contents up to the listappendend
template tag to the list named by string. The contents may
contain other templates, including listappendbegin
... listappendend. If the list does not exist, it is created. The
contents will not be emitted until a listemit template tag
which uses the name of the list is met in the processing. The
listappendend need not appear in the same string as the
corresponding listappendbegin. The listappendend ends the most
recently begun list, i.e., a stack of list names is at work.
{{ listemit string
string }}: Emits the
elements of the list named by the first string. The second
string is placed in between each list item.
{{ listclear string
}}: Clears the list named by
string (i.e., makes it empty).
Dictionary manipulation commands
{{ dictlookup
dictname-as-string feature
feature-index-as-integer default-as-string
}}: Can only be used with fetchinfo,
not renderinfo, since the features are only available in the
fetchinfo stage. Looks up the dictionary with the given name under
the "dictionaries" key of the fetchinfo stylesheet at hand, and then
looks up the key given by the feature of the current object with
feature index as given, and the emits the value, if found, or the
default given, if not found.
The feature value is mangled according to XML rules. See the
feature template tag on this page for an
explanation.
Example: {{ dictlookup 'booknames' feature 0
'Unknown book ID' }}
{{ dictlookup
dictname-as-string featurenomangle
feature-index-as-integer default-as-string
}}: This behaves just like the
dictlookup ... feature ... counterpart, but does not XML-mangle the
feature value before looking the feature value up. This can also
only be used with fetchinfo, not renderinfo.
Example: {{ dictlookup 'booknames'
featurenomangle 0 'Unknown book ID' }}
{{ dictlookup
dictname-as-string var variable-name-as-string
default-as-string }}: This
behaves just like the dictlookup ... feature ... counterpart, but
uses the contents of the given variable as the key into the
dictionary. Additionally, it can be used both in fetchinfo and in
renderinfo.
The contens of the variable are XML-mangled before the
lookup. See the feature template tag for an
explanation of XML-mangling.
Example: {{ dictlookup 'booknames'
var 'bookID' 'Unknown book id' }}
{{ dictlookup
dictname-as-string varnomangle
variable-name-as-string default-as-string
}}: This behaves just like the
dictlookup ... var ... counterpart, but does not mangle the variable
contents before looking up in the dictionary.
Example: {{ dictlookup 'booknames'
var 'bookID' 'Unknown book id' }}
{{ dictlookup
dictname-as-string counter counter-name-as-string
default-as-string }}: This
first sees if the given counter exists. If it does not, it is
initialized to 0. Then, its value is converted to string in
base-10. Then, the dictionary lookup is performed as for var and
feature, but with the counter-value as the lookup key.
Example: {{ dictlookup 'number2letter_dict'
counter 'footnotenumber' 'Unknown number' }}
Named set manipulation commands
The template language supports "named sets" of strings. The
following template actions manipulate these.
{{ namedsetaddbegin
string string }} named
set contents... {{ namedsetaddend
}} : Adds the string(s) up to the
namedsetaddend template tag to the set named by first
string. If the named set does not exist, it is created
before any string is added. The contents will not be emitted until
a namedsetemit template tag which uses the name of the set
is met in the processing.
The second string is a delimiter string
which, if non-empty, is used to cut up the content string into
substrings, which are then added one by one.
{{ namedsetremovebegin
string string }} named
set contents to remove... {{
namedsetremoveend }} : Removes the
string(s) up to the namedsetremoveend template tag from the
set named by first string. If the named set does not exist,
nothing happends.
The second string is a delimiter string
which, if non-empty, is used to cut up the content string into
substrings, which are then removed one by one.
{{ namedsetemit string
string }}: Emits the
elements of the set named by the first string, in memcmp
lexicographic order. The second string is placed in between
each set item, and may be empty.
{{ namedsetclear string
}}: Clears the set named by
string (i.e., makes it empty).
if-then-else flow control
{{ if featureequal
integer "string-in-quotes"
}}if-true-template{{
endif }}: Checks whether the string
representation of the feature given by the 0-based index
integer into the "get" list of features is equal to the
"string-in-quotes". If it is, then the template
if-true-template is executed. Otherwise, nothing is
emitted.
This also has a different variant:
{{ if featureequal integer
"string-in-quotes"
}}if-true-template{{ else
}}if-false-template{{
endif }}: Checks whether the string
representation of the feature given by the 0-based index integer
into the "get" list of features is equal to the "string-in-quotes".
If it is, then the template if-true-template is executed.
Otherwise, the if-false-template is executed.
{{ if varequal
varname-as-string 'string-in-quotes'
}}if-true-template{{
endif }}: Checks whether the variable
given is equal to the "string-in-quotes". If it is, then
the template if-true-template is executed. Otherwise,
nothing is emitted.
{{ if varequal
varname-as-string 'string-in-quotes'
}}if-true-template{{
else
}}if-false-template{{
endif }}: Checks whether the variable
given is equal to the "string-in-quotes". If it is, then
the template if-true-template is executed. Otherwise, the
if-false-template is executed.
{{ if varequal
varname-1-as-string var varname-2-as-string
}}if-true-template{{
endif }}: Checks whether the variable
varname-1-as-string equal to the
variable varname-2-as-string. If it is, then the template
if-true-template is executed. Otherwise, nothing is
emitted.
{{ if varequal
varname-1-as-string var varname-2-as-string
}}if-true-template{{
endif }}: Checks whether the variable
varname-1-as-string equal to the
variable varname-2-as-string. If it is, then the template
if-true-template is executed. Otherwise, the
if-false-template is executed.
{{ if listempty
listname-as-string
}}if-true-template{{
endif }}: Checks whether the list by
the name given is empty, or does not exist. If either of these is
true, then the template if-true-template is executed.
Otherwise, nothing is emitted.
{{ if namedsetempty
named-set-name-as-string
}}if-true-template{{
endif }}: Checks whether the set
named by the given name is empty, or does not exist. If either of
these is true, then the template if-true-template is
executed. Otherwise, nothing is emitted.
{{ if listempty
listname-as-string
}}if-true-template{{
else
}}if-false-template{{
endif }}: Checks whether the list by
the given name is empty, or does not exist. If either of these
conditions hold, then the template if-true-template is
executed. Otherwise, the if-false-template is executed.
Note about XML mangling
All other strings: Are emitted verbatim,
except that they are escaped for the XML entities '&', '<',
'>', and '"', which map as follows:
- & --> &
- < --> <
- > --> >
- " --> "
|