How ALD Applies Style to Text > Tests
  
Tests
Formatting of content is largely driven by the element that contains it. It is, however, often the case that parts of the same content within the same element are formatted differently, driven by such diverse conditions as their position in the content hierarchy, their position on the page, and other variable information. PTC ALD provides a number of ways to test this variable information and use the result:
Showstrings
Jumps and labels
Direct use of PIs
Showstrings
Put simply, a showstring is a sequence of characters introduced at various places within a document to provide the context or conditions that define which type of formatting should be applied to that particular point at that particular instance. A showstring contains a question or instruction defined by its syntax and will count, set, test, pass, call in and/or output information based on the answers to these questions. An important use of showstrings is with counters - system or user-named holding areas in system memory (x( ) counters for numbers, string counters for strings) that are given values. These values can then be queried and used to drive the application of conditional formatting.
Count: increment the value of a counter every time it is encountered.
Set: give a counter a value, which can be a number, the contents of a stream, the value of a variable, the value of an attribute, etc.
Test: verify if a certain condition or counter value exists
Pass: include specific text in an item, or transfer the value of one item (a counter, a stream, a variable) to another item so it has the same value
Call in: a <?yank> function can extract text from one place in a text stream and output it in a different location or locations by testing a variable for the new position
Output: display particular information such as page number
A showstring can be included inline in a text stream or in a paragraph style. If it appears in the text stream the requested action is only performed once. Writing it into a paragraph style will ensure its action is carried out every time the paragraph style appears. With the latter option, counters defined with the showstring are incremented and / or reset with continued appearances. In this way contextual information such as chapter numbering can be applied to a document.
Although a full description of showstrings and their uses is out of scope of this document, some examples of showstring use are detailed below, with a brief description for each one:
<?show +1x(1)>
add 1 to the value of counter x(1)
<?show =^testvar^x(1)
set the value of counter x(1) to the current value of variable ^testvar
<?show =1?x(1)[?tic=red]>
test if the value of counter x(1) is 1 and if so, change the text color to red
<?show +4?x(2)-10?x(2) $10#>
if the value of counter x(2) is greater than 4 but less than 10, insert a hard return
<?show "stream.tx"hello>
add the text "hello" to the specified text stream stream.tx
<?show "^test var2"$^testvar1>
transfer the content of variable testvar1 to variable testvar2
<?show "/section"$1,1y "/\60\\47\title\62 \/ct">
yank the text up to </title> to the stream called "section"
<?show $g>
output page number
<?show $106^(^01535)>
output the number of the last page (held by getvar 01535) in uppercase roman numerals
See the showstring dialog invoked by selecting the menu option Text > showstring.
For further information about showstrings please refer to the reference chapter Showstring Reference. This chapter is located in the Reference Manuals section of the PTC ALD Help Center, accessed via the Help menu option.
Jumps and Labels
Jumps and labels allow you to approach conditional processing in a slightly different way. They permit you introduce a set of conditions or properties and instruct PTC ALD to carry out certain actions when each one of these conditions is met. Invoking conditional processing in this way is particularly useful when working with element attributes that cannot be used directly with a PI due to potential syntactical conflicts.
The process can be made even more complex by using variable information such as the value of attributes to make up part of the target label name.
Using PIs Directly
Paragraph style tags always contain PIs and PTC ALD supports methods that allow these PIs to make formatting decisions based on certain conditional circumstances. PTC ALD can query many different sets of information and use their values or the content they contain to provide the required formatting or output:
Document hierarchy
Variables
Getvars
x( ) and string counters
XPath expressions
Mini scripts
Content can be tested using the <?yank> function
Properties can then be applied based on the result of the condition at that particular place in the content stream. For example, a paragraph can have different style requirements depending on whether it appears in a column, a table, a page number or a footnote frame. Tests can extract these different combinations of attributes and allow the addition of precise styling for each one.
Note that content can also be positioned conditionally in this way. Some ways of achieving this are given below:
Scripting and transformation methods such as XSLT and SAX can transform the content input to reflect the output.
The <?attr> PI can mark a false position in the text stream to change the formatting sequence of tags and/or elements.
It is the notion of processing logically through a text stream, a unique characteristic of PTC ALD, that permits this variety of options when producing a document.
Tests can also drive the values of the properties themselves, by populating the parameter of a PI with the result of a test that extracts the value of a variable. For example, the syntax <^?th ^var> will set the text height to the value currently held by the ^var variable.
 
PIs of this nature are not XML- or SGML-compliant.