PTC ALD in Arbortext Styler > Components of Documents and Templates > Conditional Text Formatting > Conditional Formatting > Tracking Formatting with Counters
  
Tracking Formatting with Counters
In PTC Arbortext Layout Developer each content stream has access to three different types of counter:
Numeric Counters
String Counters
FISH Variables
Counters are useful for storing information that can be used later in the formatting process. Unlike variables they are format safe, where their values track the formatting process. Counters can replace the use of XPath when it is necessary to only test previous locations in the formatting process. This often produces faster and more efficient templates. The fFormatting object has the properties counters, stringCounters, and fish, which represent the three types of counter. Use these properties to set and test counters within tags.
Use counters to store the following types of information:
Section nesting level
Numeric counters
Increment a counter when entering a section and decrement it when exiting the section. Testing the counter value extracts the nesting level much quicker than performing an XPath test to count ancestors.
Formatting settings
FISH
Formatting properties are difficult to extract so store their value in a counter if you need to test them at any point. FISH variables can be saved, stacked, and restored so are ideal for saving this type of information.
Generated content
String counters
Strings created during a formatting process often need to be reused, for example a title with additional generated text. Store the string in a string counter and reuse the value of the counter to avoid having to create the string every time it is required.
Counting children
Numeric counters
Although XPath can be used to count the children of an element, the process becomes complex, and slower, when the children have different element names. Using a counter to track this information is a simple task. It is much more efficient than using an XPath expression every time you need to evaluate the count.
One of the challenges with counters is their inability to pass their information from one stream to another. Consider using running headers to achieve this transfer of information. Refer to Running Headers for information.