Publisherintermediate
RTF Templates & Word Plugin Syntax
Explain how BI Publisher's RTF template syntax (for-each loops, conditionals, placeholders) is embedded in Microsoft Word to produce data-driven documents.
An RTF template is a Word document with BI Publisher tags in it. The Template Builder plugin inserts them; they are also plain text you can type.
It's like a mail-merge letter in Word where you don't just insert a name field — you can also tell Word "repeat this paragraph once for every item in their order" and "only show this line if their balance is overdue," all directly inside the same familiar document you're already editing.
Key Concepts
1
The basic tags.
<?ELEMENT_NAME?> insert this value
<?for-each:INVOICE_LINE?> loop over a repeating element
<?end for-each?>
<?if:AMOUNT>1000?> ... <?end if?>2
A line table is the standard pattern. Put the for-each at the start of a table row and the end at the
finish, and Word repeats the row per element:
3
| <?for-each:LINE?><?ITEM_NAME?> | <?QTY?> | <?AMOUNT?><?end for-each?> |4
One row in the template, a hundred rows in the output.
5
Grouping and sorting.
<?for-each-group:LINE;CATEGORY?> group the lines by category
<?sort:AMOUNT;'descending';data-type='number'?>6
Note the data-type on the sort. Without it, amounts sort as text, so 1000 comes before 200 — a defect that
looks like a data problem and is a template one.
data-type
7
Totals and counts.
<?sum(current-group()/AMOUNT)?>
<?count(LINE)?>8
Conditional formatting and sections.
<?if:STATUS='OVERDUE'?>PAYMENT OVERDUE<?end if?>
<?if@row:AMOUNT=0?> hide the whole row
<?start:body?> ... <?end body?> control page headers and
footers per section9
The one that causes most support calls: page breaks per group.
<?for-each:CUSTOMER?>
...
<?split-by-page-break:?>
<?end for-each?>10
Each customer starts on a new page. Without it a hundred invoices run together.
11
Two practical points.Test with real data. A template built against three sample lines looks fine and breaks with forty, because
the table spans a page and the header does not repeat. Word's "repeat header row" setting handles it and is
easy to forget.
12
The XML element names must match exactly, including case. A tag referring to InvoiceAmount when the data
model produced INVOICE_AMOUNT renders blank — no error, just an empty space where a number should be,
which is the most common "why is this field empty" cause.
InvoiceAmountINVOICE_AMOUNT
13
What the interviewer is probing.1. "How is logic expressed in an RTF template?" Probing: the mechanics. Stalls: "In Word."
Moves up: form fields holding XSL or simplified syntax — for-each, if, and field placeholders
bound to XML element names.
14
2. "What does a for-each group do?" Probing: the structure. Stalls: "Repeats." Moves up:
repeats the enclosed block per element, which is how detail lines are rendered under a header.
15
3. "What is the most common beginner mistake?" Probing: experience. Stalls: "Formatting."
Moves up: typing the syntax as visible text instead of into a form field, so it prints literally
rather than executing.
16
4. "How do you debug a template that renders nothing?" Probing: the method. Stalls: "Rebuild
it." Moves up: check the sample XML against the element names and the grouping path — a case or
path mismatch produces an empty section silently.