Setting how data is formatted and calculated

Define the content of a template element or its property values for formatting and calculating data.

About this task

You can define the content of a template using simple values, data expressions, or script expressions.

Both data expressions and script expressions have internal variables available for you to select.
Table 1. Rational Publishing Engine internal variables
Variable Description
_cell_number The cell number in a current row. If the element is not a cell, the value is 0. You can use _cell_number from either the Data expression or the Script expression tab.
_element_id The element number within the template. Kept internally in the template and used for debugging. You can use _element_id from either the Data expression or the Script expression tab.
_element_level The recursive level of an element. If there is not a value set for the element in the Recursive Level property in the Data tab, the value is 1. You can use _element_level from either the Data expression or the Script expression tab.
_row_number The row number in a current table. If the element is not contained by a row element, the value is 0. You can use _row_number from either the Data expression or the Script expression tab.
_sessionInfo Run time property information from the template or document specification. In the Script expression tab, select the _sessionInfo variable and enter the script. Use empty quotation marks without a value inside to generate the default value for the property in the output. Script examples:

_sessionInfo.getDocspecProperty("property", "");
_sessionInfo.getTemplateProperty("property", "");
_sessionInfo.getDatasourceProperty("data_source_name","property", "");
_sessionInfo.getOutputProperty("output_type","property", "");
_sessionInfo.docspecVersion
_sessionInfo.templateVersion
_sessionInfo.engineVersion
_sessionInfo.buildNumber

For the getDocspecProperty, you can use existing document specification properties or create custom metadata properties.

_sessionLogger For debugging purposes, you can display customized information, error, warning, or debugging messages in the TEMP\rpe\rpe.log file, Console view, or Problems view. The messages display in the location that is defined in the log4j.properties file.

The default setting is to display information messages in the Console view, but not in the rpe.log file.

In the Script expression tab, select the _sessionLogger variable and enter the script. You can generate log entries with one of the following methods:
  1. _sessionLogger.debug(message)
  2. _sessionLogger.info(message)
  3. _sessionLogger.error(message)
  4. _sessionLogger.warn(message)

When deciding what to enter as the message in your script, consider using a visual callout, like your initials or user name, and using variables from your template to make meaningful messages.

_sessionUtils In the Script expression tab, you can use this variable to run a function on the script called tidyXHTML. This variable is useful when you notice blocks of white space in the output that is created by improper XHTML coding. With the _sessionUtils variable, a string argument is processed and the XHTML is cleaned up so that the extra white space does not display in the output.

Example: _sessionUtils.tidyXHTML(text);

When you use the _sessionUtils variable, also select the XHTML Input and XHTML Output options in the Script expression tab.
Note: Templates that include this variable can be loaded into older versions of Rational Publishing Engine, but the scripts cannot be evaluated correctly.

Procedure

  1. In the template content editor, double-click the text element. The Set content for current element window opens.
  2. Specify the content by using one of the following options:
    • To use a simple value, click the Simple value tab and enter a value.
    • To use a data expression, click the Data expression tab and either:
      • Expand Variables and select a variable to use.
      • Expand Attributes and select a data attributes to use.
    • To use a script expression, click the Script expression tab.
      • Expand Variables, select a variable, and enter the JavaScript code that can use the variables in the current context.
      • Expand Attributes, select an attribute, and enter the JavaScript code that can use the data attributes in the current context.
      • If you copied the script from XHTML, you can select the XHTML Input option to allow the XHTML tags contained in the script to be edited.
      • If you are generating the template into XHTML output, you can select the XHTML Output option to parse the script and render the script as rich text.
      For example, to select the attributes as absolute number, name and value, enter the JavaScript code as:
      "object:"+Absolute Number+
      "attribute"+name+
      "value"+_value
      Tip: If you have a fairly complex template, you can describe each block in the template using Name and Description properties. The name and description fields are empty by default, the name content displays in the template, and the description content can be displayed in the template element hint field. This can help others reuse the template.

      You also have the option of importing an existing script or working in the JavaScript editor instead of the Script expression tab:

    1. If you are including a new script from another file, click Include script and select a file from your computer, a remote server, or from the Central Management component. Click OK to close the window and double-click the element to open the Input code for JavaScript code element window again.
    2. Click Open in editor to enter the script in an Eclipse JavaScript editor. The script opens in a new editor tab as a temporary .js file and you can edit the JavaScript.
      Note: If you begin typing and after entering a period or another character as a value, an Error accessing JavaScript file message might appear. It might also be followed by a Problems during content assist message. If you encounter these messages, complete the instructions in the message to disable the Other JavaScript Proposals option:
      1. Click Window > Preferences > JavaScript > Editor > Content Assist > Advanced.
      2. In the Content assist cycling section, clear the Other JavaScript Proposals option.
      3. Click OK to close the window.
    3. Manage the script through the options in the Outline view.
    4. Save the changes.
    5. Close the temporary JavaScript editor tab. You are returned to the Input Code for JavaScript Code Element window.
    6. Click Test script to validate the code.
    7. Click OK to save the changes and exit the window.
  3. Click OK to save the changes.

Example

Data expression usage example
To display automatically generated row numbers in your tables:
  1. Drag a table element into the editor.
  2. Enter the 3 rows and 3 columns for the table and click OK.
  3. Drag a text element into each cell.
  4. Select the first cell in the first row.
  5. In the Properties view, select the Content tab and click Configuration icon. Double-clicking the element also opens the same window.
  6. Click the Data expression tab and select _row_number. Then click OK.
  7. Repeat for the first cell in the second row and the third row.
  8. Remove the borders from the row number cells:
    1. Hold the CTRL key and select the first cell in each row. When you have multiple elements selected, you can edit the properties for all of them at the same time.
    2. In the properties view, select the Border tab.
    3. For the Style property, select none.
  9. Save the template.
  10. Test the template by generating the output. The first cell includes the row number and does not have borders around it:
    Output example
  11. In the template, finish adding attributes from your data source schema to the remaining cells to complete the table.

Feedback