About Arbortext Styler > Styling Custom Tables > Generating Custom Table Cells via XPath
Generating Custom Table Cells via XPath
This section describes how to use XPath expressions to create cells for a custom table where no table cell elements appear in the document model. You may also create header rows for the custom table in this way.
The example assumes the use of a PartList element, which has the following content model:
<!ELEMENT PartList (Part+)>
<!ELEMENT Part (Number, Description, Weight, Height, Width)>
In addition, the Weight element has an attribute unit, and the Part element has an attribute type.
Example: Generating custom table cells and header rows via XPath
Using this example you will create a custom table based on the PartList element, with rows based on the Part element. The columns in the rows are based on the following document elements and attributes:
The type attribute of the Part element
The unit attribute of the Weight element
You will also generate header rows for the table.
1. In your source document, add a PartList element, with Part elements as its children. Create child elements Number, Description, and Weight for Part. Give the elements some content.
Give a value to the type attribute of the Part element.
Give a value to the unit attribute of the Weight element.
2. Open your stylesheet for edit.
3. In the Custom Tables list, create a new custom table object where the PartList element takes the Table role.
4. In the Elements category for the Custom Tables list, create roles in the custom table for the child elements of Partlist:
Part: Row
Number: Cell
Weight: Cell
Description: Cell
5. Navigate to the Cells category.
6. In the Generated Cells field, click the New button. The New Generated Cell dialog box opens.
7. Enter a generated cell definition that will extract the content of the type attribute of the Part (current row) element:
Name: user defined, e.g. Part-type
XPath: @type
Click OK to exit the dialog box. The generated cell definition Part-type appears in the Generated Cells field and at the end of the Cell Order field.
8. Create a second generated cell definition using the Generated Cell dialog box as above. Configure it to extract the content of the unit attribute of the Weight element:
Name: user defined, e.g. Weight-unit
XPath: Weight@unit
Click OK to exit the dialog box. The generated cell definition Weight-unit appears at the end of the Generated Cells and Cell Order fields.
9. In the Cell order field, select Part-type and use the up arrow to move it to the second position in the list. Select Weight-unit and move it up to follow Weight.
The order of the columns is now:
Note that the Specified button has been selected for you. This occurs automatically when you enter the first generated cell definition.
10. You may want to generate header rows for the tables too. The next steps will generate the following headers for the columns:
Part Number
Part Type
Unit Weight
11. Navigate to the Header Cells category for your custom table. Click the New button next to the Generated Header Cells field to open the New Generated Header Cell dialog box .
12. In the Name field, enter a name of your choice to identify the header cell definition.
13. In the XPath field, enter the text you want to output in the header cell, surrounded by single quotes.
If you want to localize the generated text in the header cells, use the following alternative process to configure it:
a. Enter an empty string in the XPath field, i.e. ' ', then click OK to exit the New Generated Header Cell dialog box.
b. Navigate to the SFE generated for the header cell, i.e. _sfe:GeneratedHeaderCell_xxx_yyy. See SFEs created for generated cells for further information on SFEs.
c. Enter the required generated text for the header cell as the generated text for the SFE.
Refer to Maintaining Translations of Generated Text for information on translating generated text.
14. Click OK to exit the dialog box.
15. Repeat these steps until you have generated header cell definitions that will provide a header title for each of the columns defined in the Cells category, for example:
Column in Header Cells
'Part Number'
'Part Type'
'Unit Weight'
16. If necessary, use the up and down arrows in the Header cell order field to reorder the header cell definitions.
17. Preview your document for print. You will see that the columns in the PartList custom table are ordered in the correct way, and contain the content of the specified elements and attributes.
SFEs created for generated cells
Arbortext Styler automatically creates SFEs to support generated cell definitions. This allows you to configure font properties and other properties that can normally be configured for table cell elements:
For generated cells: _sfe:GeneratedCell_xxx_yyy
For generated header cells: _sfe:GeneratedHeaderCell_xxx_yyy
For generated header rows: _sfe:GeneratedHeaderRow_yyy
Note that this SFE only includes the custom table name suffix since you do not supply a name for a generated header row definition.
Where xxx is replaced by the value of the Name field from the Cells or Header Cells property categories for the generated cell definition and yyy is replaced by the name of the custom table.
These SFEs are always kept in the same module as the custom table they correspond to. They cannot be deleted, moved or copied to different modules by themselves. When the custom table definition is deleted, moved or copied, the SFEs are also deleted, moved or copied. If the custom table is renamed, or if the generated cell or header cell is renamed, the corresponding SFE is also renamed. This includes renaming references to the SFE, for example in the selector of a context.
Support for cell generation in custom tables
The table below shows support for table cell generation in available output formats with a .style stylesheet.
Editor view
Generated cells are not shown
Print / PDF via PTC ALD
Print / PDF via FOSI
Print / PDF via XSL-FO
All HTML outputs
Bear in mind these general guidelines when working with custom tables:
Column reordering using generated cells is not supported in any format of stylesheet exported from Arbortext Styler.
If all cells within the table row of a custom table are generated, the table will always be shown in markup form in Editor view. It will not be displayed as a table.
To test an XPath expression for generating table cells
It often takes multiple attempts to define the correct the correct XPath expression to meet your requirements. It is much quicker to develop and test expressions Arbortext Editor than in Arbortext Styler - the steps below explain how:
1. Open your document in Arbortext Editor.
2. Expose the table markup via the View > Tables > Markup menu option.
3. To test an expression that will generate a cell and its content, place the cursor just inside a row element and enter this command in the command line:
eval oid_xpath_string(oid_caret(), 'your xpath expression here')
The command will return the string that will become the generated cell’s content.
4. To test an expression that will generate a header cell and its content, place the cursor inside the header row element and use the command shown above. If there is no header row element, place the cursor just inside the table element and use the command.
Translatable generated text for generated header cells