About Arbortext Styler > Creating Contexts > Working with Contexts
  
Working with Contexts
This topic describes how to create, edit, and delete an element context.
To Create a Context for an Element
1. In Arbortext Styler, elect to display in the Elements list either the elements that are permitted by your doctype or all elements included in the stylesheet by checking or unchecking the View > Only Elements in Document menu option.
2. Choose Options > Show Contexts as XSL if you want to view contexts in XSL syntax. For example, if you create a context for title within chapter, the XSL version displays as chapter/title whilst the default text version would display as title in chapter.
3. Select from the Elements list the element for which you wish to create a context. Note that the element must have had a style applied before you can create the context. Choosing an element selects the element and all its contexts.
4. Choose Insert > Context to display the Context dialog box. The selected element displays in the Context window.
5. Click New Ancestor if you want to specify that the element has to occur inside an ancestor element, then select an element from the drop down list of valid ancestors. The selected ancestor is displayed two levels above the original element, with an intervening asterisk, or wildcard, that signifies that there could be any number of elements in between the element and the ancestor (or no elements between them).
Click New Parent if you want to specify that the element has to occur immediately within a specific element, then select an element from the drop down list of valid parents. The parent is displayed one level above the immediate element.
* 
If you are creating a context for a UFE, you may see the warning dialog box shown below if you try to assign a parent element that is not another UFE or a SFE:
This is an image of a warning dialog box asking you to confirm if you wish to change “book” from a parent to an ancestor of “_ufe:booksubtitle”
Since UFEs are used to format items in generated text, those items will also be wrapped with a SFE element that marks generated text, such as _sfe:BeforeOrAfterText. As such the element that appears to be the parent of the UFE may not be its direct parent. For example, if you insert a UFE to format a generated title in a division based on a chapter element, the hierarchy for the title in that element will be as shown below.
<chapter>
<_sfe:BeforeOrAfterText>
<_ufe:Title>Introduction</_ufe:Title>
</_sfe:BeforeOrAfterText>
</chapter>
The chapter element is therefore an ancestor of the UFE, not its direct parent. You should create the context _ufe:Title anywhere in chapter.
You can repeat this step for any of the elements in your context specification (the original element, or any parent or ancestor). That is, you can specify a parent or ancestor for a parent or ancestor. To do this, select the element in the context window, and click New Ancestor or New Parent.
6. Select a Position to further refine the context by specifying, for any element in the context specification, its position relative to sibling elements of the same type. Select the element you want to qualify with a position, then select a position from the Position drop down list.
If you select XPath Predicate from the list, you will be presented with the XPath Predicate dialog box, in which you must enter a valid XPath predicate.
* 
You must understand XPath and its syntax to use this option. Refer to the World Wide Web Consortium (W3C) web site (http://www.w3.org/TR/xpath) for information on the XPath standard.
Refer to Using XPath in contexts for some guidelines on including XPath predicates to define position information.
7. Select At top level if you want the context to apply only when the highest ancestor or parent element of the context is the top-level element in the document.
8. Click OK to save the new context and exit the Context dialog box. The context is added to the selected element in order of priority, from highest to lowest (the more specific the context, the higher its priority).
* 
Be careful when reordering contexts. Reordering contexts changes their priority and thus affects formatting.
To Edit a Context
1. In Arbortext Styler, choose the context you want to edit from the Elements list.
2. Choose the Edit > Edit Context menu option to display the Context dialog box.
3. Select the parent, ancestor, or wildcard element you want to edit and click Edit.
4. Select from the drop down menu the element with which you want to replace the highlighted parent, ancestor, or wildcard element. Repeat as necessary.
5. Click OK when you are finished to save your change and exit the Context dialog box.
To Delete a Context
1. In Arbortext Styler, choose the context you want to delete from the Elements list, then choose Edit > Delete.
* 
You can select multiple contexts for deletion.
2. A message asks you if you want to delete the selected item. Select Yes to delete the context.
Example: Formatting Left and Right Indents for a Context
The following example describes how to format left and right indents. You can add left, right, hanging, and block indent formatting to block styled elements (note: indents are not permitted for elements styled as inline, i.e. where the Structure type option in the Breaks category is set to Inline).
* 
If an element configured in the DTD or schema to have the xml:space=”preserve” attribute set is added to the stylesheet during either a New Stylesheet operation, or by choosing Insert > Add Elements from document or Doctype, its style will be set automatically to Preformatted. Arbortext Styler will not allow the style to be changed. When an element’s style is Preformatted, it has a value of Preformatted for the Alignment field in the Indent category and you will not be able to change this setting.
1. Open the transport.xml document 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. In Arbortext Styler, click on the para element.
5. Choose Elements > New Context to display the Context dialog box.
6. In the Context dialog box, click New Parent, select important from the list, and press ENTER.
7. Click OK.
8. Select the para in important context from the Elements list, then go to the Indent category.
9. Set Alignment to Left if it isn't already set.
10. Set Left to 2.00in, and set Relative to to Left margin.
11. Choose Preview > Print.
12. In the Print Preview window, locate the “Important Note” within the Moon Rover section. Note that the content of the para within the important element is now indented from the left side.
13. In Arbortext Styler, select the para in important context from the Elements list, and then go to the Indent category.
14. Set Alignment to Left if it isn't already set.
15. Set Right to 2.00in, and set Relative to to Right margin.
16. Choose Preview > Print.
17. In the Print Preview window, locate the “Important Note” within the Moon Rover section. Note that the content of the para within the important element is now indented from the right side, as well as the left. This is often referred to as a block indent.
18. In Arbortext Styler, select the important everywhere context from the Elements list, and then go to the Indent category.
19. Set the value in the Left field to 1in, but change Relative to to Left margin.
20. Set the value in the Right field to 1in, but change Relative to to Right margin.
21. Select the para in important context from the Elements list, and then go to the Indent category.
22. Leave the current value in the Left field, but change Relative to to Parent left indent.
23. Leave the current value in the Right field, but change Relative to to Parent right indent.
24. Choose Preview > Print.
25. In the Print Preview window, locate the “Important Note” within the Moon Rover section. Note that the content of the para within the important element is now indented even more from the right and the left sides.
Changing the Relative to values accounts for the change in indentation. Instead of calculating the left and right indents of the para in important context based on the left and right margins, the left and right indents were calculated based on its parent element's (important everywhere) left and right margins. So the left and right indents of the para in important context (2 inches) were added to the left and right indents of the important everywhere context (1 inch) to obtain the value that was applied (3 inches).