Tables

A table is a visual component that usually iterates over the data it contains. You typically create a table when you want your report to display multiple rows with two or more columns of dynamic data - one row for each movie in the videos.xml file, with each row containing the movie's title, its genre, and its rating, for example.

Figure 454. Example Table and Output

If your data can be displayed in a single column (only movie titles, for example), you might want to consider using either the list or repeater components. See Lists and Repeaters for more information.

Creating a Table

The easiest way to create a table in XML Publisher is to drag and drop a repeating element. When you drop the repeating element on the canvas, Stylus Studio displays a short-cut menu with an Insert Table choice. You can insert a table with either

  • Populated Columns - Stylus Studio creates a table with one column for each of the child nodes of the repeating element. The table's context and XPath are set based on the repeating element used to create it. Each column contains a data value glyph representing a child node.
  • Empty - Stylus Studio creates table with three empty columns. As with the previous option, the table's context and XPath are set based on the repeating element used to create it, but it is up to you to select from the data sources pane the child nodes you want to include in the table.

You can also create a table manually ( Report > Insert > Table, or select Insert Table from the canvas short-cut menu). When you create a table like this, however, the context and XPath are not set for you, and it will only contain the number of rows you explicitly create for it unless you also define the Loop property for a row.

Graphical Representation

Tables, like the one shown in Figure 455, are displayed as a single row with a loop symbol ( ); the loop symbol indicates a repeating row.

Figure 455 shows a table based on the book repeating element in books.xml that was created using the Populated Columns short-cut menu choice.

Figure 455. Table Created with Populated Columns

Figure 456 shows a table based on the same repeating element, but it was created using the Default Columns short-cut menu choice.

Figure 456. Table Created with Default Columns

Finally, Figure 457 shows a table that was created manually using the Report menu. Notice that it does not have the loop symbol associated with repeating rows.

Figure 457. Manually Created Table

Sorting

By default, data for dynamic rows is displayed in document order. You can use an XPath expression in the Loop property's Sort sub-property to specify a different sort order. The Loop property appears on the Row tab of the Properties window.

Adding Rows and Columns

To add rows and columns to a table:
1. Select the cell before or after which you wish to add a row or column.
2. Right-click.

Stylus Studio displays a short-cut menu.

Alternative: Click the Report > Table menu.

3. Select the appropriate choice from the menu.

Deleting Rows, Columns, and Tables

To delete a row, column, or table:
1. Select a cell in the row or column you want to delete.
2. Click the Delete button in the toolbar ( ).

Stylus Studio displays a drop-down menu.

Alternative: Right-click.

Alternative: Click the Report > Table menu.

3. Select the appropriate choice from the menu.
 
Free Stylus Studio XML Training: