The <format/> command

This command can be used to format one or more numbers into a string. The result can either be processed as input or assigned to a variable.

There are two required arguments:

  • The value attribute contains the numbers to be processed.

  • The template attribute contains a formatting string.

If the optional var attribute is present it is used as the name of the variable to which the result is assigned. If the attribute is not present the result is processed as input.

The value is used to produce a list of numbers by extracting strings of digits (0-9). Non-digits are ignored except as separators. There must be at least one digit string in the value.

The template is copied to the result except that the following characters are replaced by a number:

  • # is replaced by a decimal number

  • a is replaced by a lower-case alphabetic string

  • A is replaced by an upper-case alphabetic string

  • i is replaced by a lower-case roman numeral

  • I is replaced by an upper-case roman numeral

The alphabetic strings use the sequence a,b,c, ... z,aa,ab,ac, .... A zero value is displayed as “0” regardless of the format chosen.

Formatting characters in words are ignored. For example, in the template “Section A” the “i” is ignored and the “A” is replaced.

Each number in the value list should have a corresponding replacement character in the template. If there is a mismatch a warning will be generated.

Examples

The command

<format value="7" template="[I]"/>

produces the output [VII].

Assuming that the variables Chapter and Section contain 12 and 5 respectively, the command

<format var="Label" value="{Chapter}-{Section}" template="Part #.a"/>

sets the variable Label to the value Part 12.e.