Stylesheet Development with PTC ALD > Adding PTC ALD Code to Stylesheet Source > Samples > Counters and Variables > Use PTC ALD Counters and Variables
  
Use PTC ALD Counters and Variables
Samples directory: Arbortext-path/samples/ALD/CountersAndVariables
Sample file: countersAndVariables.xml
Main stylesheet: countersAndVariables.style
Stylesheet modules: baseStylesheet.style and countersAndVariablesPropertySets.style
The sample is based on the standard axdocbook document type. It demonstrates how to set, increment, display, and reset the values of counters and variables.
Some information about PTC ALD’s counters and variables is given below:
Numeric counters
A numeric counter increments by a specified number every time an element that references it is encountered within a particular scope. The current value of a counter can be manipulated or tested at any point in a document to provide context-specific formatting. You may also choose to simply display its value.
In traditional PTC ALD syntax, numeric counters are called x counters. They can be accessed via PTC ALD's original show string mechanism using the syntax x(), where the number in parentheses indicates which counter slot is being used. PTC ALD has 200 numeric counter slots available, the first 10 being reserved for use by Arbortext Styler. Within an Arbortext Styler stylesheet, the counters are accessed via the counters property of the fFormatting object. This property is an array of integers.
Numeric counters (x counters) are described as format safe. PTC ALD will remember their values inline with the formatting process. Page up and down actions will have no effect on their value.
String counters
A string counter allows users to store a text string of up to 3500 characters in length (approx). The current value of a string counter can be manipulated or tested at any point in a document to provide context-specific formatting. You may also choose to simply display its value.
PTC ALD has 100 string counters available, but as with numeric counters the first 10 are reserved for use by Arbortext Styler. Within an Arbortext Styler stylesheet, the counters are accessed via the stringCounters property of the fFormatting object. This property is an array of strings.
String counters are described as format safe. PTC ALD will remember their values inline with the formatting process. Page up and down actions will have no effect on their value.
Global variables
PTC ALD works with two types of global variable:
1. Variables that are created and managed by JavaScript
2. Variables that are managed by PTC ALD itself
The samples deal with PTC ALD’s own global variables.
You may create any number of global variables in PTC ALD and name them as required. Within an Arbortext Styler stylesheet, PTC ALD global variables are accessed via the variables property of the fApplication object. This property is an array of scalar system variables.
JavaScript variables are format safe, whereas properties on objects are not.