Control the Placement of Instructions Using the Context Commands

The Publisher syntax is simplified XSL instructions. This syntax, along with any native XSL commands you may use in the template, is converted to XSL-FO at runtime. The placement of these instructions within the converted stylesheet determines the behavior of the template.

Publisher's RTF processor places these instructions within the XSL-FO stylesheet according to the most common context. However, sometimes you must define the context of the instructions differently to create a specific behavior. To support this requirement, Publisher provides a set of context commands that allow you to define the context (or placement) of the processing instructions. For example, using context commands, you can:

  • Specify an if statement in a table to refer to a cell, a row, a column or the whole table.

  • Specify a for-each loop to repeat either the current data or the complete section (to create new headers and footers and restart the page numbering)

  • Define a variable in the current loop or at the beginning of the document.

You can specify a context for both processing commands using the Publisher syntax and those using native XSL.

  • To specify a context for a processing command using the simplified Publisher syntax, simply add @context to the syntax instruction. For example:

    • <?for-each@section:INVOICE?> - Specifies that the group INVOICE should begin a new section for each occurrence. By adding the section context, you can reset the header and footer and page numbering.

      If you do not want to restart the page numbering, then add the command: <?initial-page-number:'auto'?> after the @section command to continue the page numbering across sections.

    • <?if@column:VAT?> - Specifies that the if statement should apply to the VAT column only.

  • To specify a context for an XSL command, add the xdofo:ctx="context" attribute to the tags to specify the context for the insertion of the instructions. The value of the context determines where the code is placed.

    For example:

    <xsl:for-each xdofo:ctx="section" select ="INVOICE">

    <xsl:attribute xdofo:ctx="inblock" name="background-color">red</xsl:attribute>

Publisher supports the context types that are described in the following table:

Context Description

section

The statement affects the whole section including the header and footer. For example, a for-each@section context command creates a new section for each occurrence - with restarted page numbering and header and footer. Note that you can retain continuous page numbering across sections by using the <?initial-page-number:'auto'?> command. See Create Batch Reports for an example of this usage.

column

The statement affects the whole column of a table. This context is typically used to show and hide table columns depending on the data. See Format Columns for an example.

cell

The statement affects the cell of a table. This is often used together with @column in pivot tables to create a dynamic number of columns. See Insert Pivot Tables for an example.

block

The statement affects multiple complete fo:blocks (RTF paragraphs). This context is typically used for if and for-each statements. It can also be used to apply formatting to a paragraph or a table cell. See Highlight Cells for an example.

inline

The context becomes the single statement inside an fo:inline block. This context is used for variables.

incontext

The statement is inserted immediately after the surrounding statement. This is the default for <?sort?> statements that must follow the surrounding for-each as the first element.

inblock

The statement becomes a single statement inside an fo:block (RTF paragraph). This is typically not useful for control statements (such as if and for-each) but is useful for statements that generate text, such as call-template.

inlines

The statement affects multiple complete inline sections. An inline section is text that uses the same formatting, such as a group of words rendered as bold. See Use If Statements in Boilerplate Text.

If you use @inlines with if syntax, any other if syntax inside the statement must use the context command @inline. If you use @inlines with FOR-EACH syntax any other if or FOR-EACH syntax inside the statement must use the context command @inline.

begin

The statement is placed at the beginning of the XSL stylesheet. This is required for global variables. See Set Parameters.

end

The statement is placed at the end of the XSL stylesheet.

The following table shows the default context for the Publisher commands:

Command Context

apply-template

inline

attribute

inline

call-template

inblock

choose

block

for-each

block

if

block

import

begin

param

begin

sort

incontext

template

end

value-of

inline

variable

end