About Arbortext Styler > Creating Conditions > Creating If, Else/If, and Else Conditions
  
Creating If, Else/If, and Else Conditions
This topic describes how to create If, Else If and Else conditions. Using conditions of this nature reduces the need to explicitly test every possible combination of condition tests and allows you to work with more robust and concise statements.
Suppose you have a list item element with a role attribute that specifies the text style to be applied to its contents. As an example, you could want to set the following four conditions for the context:
If role=”normal” or if role does not have a value, the contents of the list item should be displayed in normal text.
If role=”italic”, the content should be displayed in italic text.
If role=”bold”, the content should be displayed in bold text.
If role has any other value, the contents should be shown in red text.
In order to achieve the desired formatting of the list, you can specify conditions for the required context of the list item element.
Example: Creating If, Else/If, and Else Conditions
1. In Arbortext Editor, open the file transport.xml located at Arbortext-path/samples/styler.
2. Choose File > Save As to create a local copy of transport.xml.
3. Choose Styler > Edit Stylesheet to open the associated stylesheet for edit. This is a read only stylesheet so you will need to save a local copy if you want to make amendments.
4. Locate the first itemizedlist in the document. Set the attributes for the listitem entries as shown below (note that the value of the attribute on the last listitem is deliberately misspelled):
This is an image of the itemizedlist in the document with the value of the role attribute on the last entry spelled “italc” instead of “italic”
5. In Arbortext Styler, select the listitem in itemizedlist context of the listitem element in the Elements list.
6. Choose the Insert > Condition menu option. The New Condition dialog box opens.
7. Ensure that If is selected in the Condition type field. Click the New Attribute Test button to open the New Attribute Test dialog box.
8. Ensure that the Current element option is set to listitem in the Test attribute of field. Select role from the Attribute name field, and set the Attribute value field to Comparison = normal.
9. Click OK to save the condition and exit the dialog box. The test appears in the Tests area of the New Condition dialog box.
10. Again ensuring that If is selected in the Condition type field, click the New Attribute Test button.
11. In the New Attribute Test dialog box, ensure that the Current element option is set to listitem in the Test attribute of field. Select role from the Attribute name field, and set the Attribute value field to Not assigned any value.
12. Click OK to save the test and exit the dialog box. The test appears in the Tests area of the New Condition dialog box, separated from the previous test by the word “AND”.
13. In the Condition is true if field, select Any test is true. The two tests are now separated by the word “OR”, indicating that a particular set of formatting properties should be applied if either of these tests return true.
14. Click OK to save the condition and exit the dialog box. The condition is now displayed for the listitem in itemizedlist context in the Elements list, described as If attribute “role=”normal” or attribute “role” is not assigned any value.
15. Choose the Insert > Condition menu option to set up the next condition.
16. In the New Condition dialog box, ensure that Else If is selected in the Condition type field. Elect to create a new attribute test.
17. In the New Attribute Test dialog box, ensure that the Current element option is set to listitem in the Test attribute of field. Select role from the Attribute name field, and set the Attribute value field to Comparison = italic.
18. Click OK to save the test and exit the dialog box.
19. Click OK to save the condition and exit the New Condition dialog box. The condition is now displayed for the listitem in itemizedlist context in the Elements list, described as Else if attribute “role”=”italic”.
20. Choose the Insert > Condition menu option to set up the next condition.
21. In the New Condition dialog box, ensure that Else If is selected in the Condition type field. Elect to create a new attribute test.
22. In the New Attribute Test dialog box, ensure that the Current element option is set to listitem in the Test attribute of field. Select role from the Attribute name field, and set the Attribute value field to Comparison = bold.
23. Click OK to save the test and exit the dialog box.
24. Click OK to save the condition and exit the New Condition dialog box. The condition is now displayed for the listitem in itemizedlist context in the Elements list, described as Else if attribute “role”=”bold”.
25. Choose the Insert > Condition menu option to set up the next condition.
26. In the New Condition dialog box, ensure that Else is selected in the Condition type field. All options in the New Condition dialog box are disabled, since the formatting properties for this condition apply in all other cases and as such do not need tests to verify a match.
27. Click OK to save the condition and exit the New Condition dialog box. The condition is now displayed for the listitem in itemizedlist context in the Elements list, described as Else.
This is an image of the listitem in itemizedlist element in the Elements list, displaying the 4 conditions that have been created
28. The next step is to set up the formatting properties for each of the conditions you have created. Highlight each condition in turn in the Elements list, and specify the characteristics shown below in the Text category:
If attribute “role”=”normal” or attribute”role” is not assigned any value - Set Font size to 12pt
Else if attribute “role”=”italic” - Set Font size to 12pt and Italic to Yes.
Else if attribute “role”=”bold” - Set Font size to 12pt and Bold to Yes.
Else - Set Font size to 12pt and Text color to Red.
29. Choose Preview > Print. In the Print Preview window, note how the text for each list entry has been displayed based on its individual condition. Note specifically that the first two entries have been shown in normal text, as a result of the If attribute “role”=”normal” or attribute”role” is not assigned any value condition, and that the final entry has been shown in red text, as a result of the Else condition. In the latter case you have identified an attribute value name that has been accidentally misspelled.