About Arbortext Styler > Cross References and Other Links > Creating Cross References and Cross Reference Formatting > Cross Referencing to an Alternative Title Element
Cross Referencing to an Alternative Title Element
The procedure detailed below describes how to cross reference to a chapter that can include both a title and a subtitle element. The cross reference will be configured so that it points to the subtitle element if one exists for the chapter, or to the regular title element if a subtitle does not exist. The procedure uses the existing cross reference format object Label Number Text as its basis.
1. In Arbortext Editor, open the transport.xml sample document located at Arbortext-path/samples/styler.
2. 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.
3. Back in Arbortext Editor, add a subtitle element directly after the title in the second chapter, and add some alternative title text.
4. Give the id attribute of the second chapter element a value of chap2, and set the value of the same attribute on the third chapter to chap3.
5. Add two xref elements into the text somewhere at the beginning of the document - one with the attribute linkend=”chap2”, i.e. pointing to the second chapter, and one with the attribute linkend=”chap3”, i.e. pointing to the third chapter. Note that neither cross reference currently displays any link text.
6. In Arbortext Styler, give the subtitle element the Title style via the Edit > Style menu option. If the element already has this style, you can skip this step.
7. Create a context for the subtitle in a chapter, and style it as required.
8. In the Cross References list The Cross References list icon - blue rectangles in the top left and bottom right corners, connected by a red arrow, copy the Label Number Text cross reference format object, and paste the copy into the same list with a new name, for example Label Xref Title.
9. In the properties list for the object, click the Edit button to open the Generated Text Editor. Place your cursor to the right of the existing ElementContent element, and choose the Edit > Modify Attributes menu option. The Modify Element Content dialog box opens.
10. Select the By XPath and Insert only content options, and add the XPath expression shown below to the field:
Note that the expression assumes the context node for the expression is the title element. The expression will select subtitle if it exists, or title if a subtitle does not exist.
Click OK to save the content setting and exit the dialog box. Click File > Apply and Close to exit the Generated Text Editor.
11. In the Elements list, give the xref element the Cross Reference style if this has not already been done, via the Edit > Style menu option. If the element already has this style, choose the Edit > Edit Style Details for the element. In either case, the Cross Reference Details dialog box opens. Configure the settings for the cross reference object as shown below, then click OK to exit the dialog box.
Reference attribute - linkend
Select a cross reference format - Label Number Text
Here you have styled any cross references that point to elements other than chapter such that they will use the Label Number Text format to output the chapter number and title text as the link text.
12. Still in the Elements list, create a condition for the xref element, via the Insert > Condition menu option. The Condition dialog box opens.
13. Choose the New XPath Test button to open the XPath test dialog box. In the expression field, enter the XPath expression shown below:
Click OK twice to save the condition and exit the two dialog boxes. The condition If XPath expression (name(id(@linkend))=’chapter’) is true now appears in the Elements list.
14. Navigate to the Generated text category for the condition and click the Edit button next to the After-text field. In the Generated Text Editor, modify the attributes of the existing CrossReference element and change the value of the Cross reference format field to Label Xref Title. Click OK to save the change and exit the dialog box. Click File > Apply and Close to save the generated text setting and exit the editor.
Here you have styled cross references that point to chapter elements such that they will use the Label Xref Title format to output the chapter subtitle if it exists, or the chapter title if a subtitle does not exist, as the link text.
15. Choose Preview > Print. In the print preview window, note that the cross reference to the second chapter outputs the chapter's subtitle as its link text, while the cross reference to the third chapter has the chapter's title as its link text.
Note also that the subtitle for the second chapter is included in the table of contents (TOC) for the document. This is because it is styled as a title context and given the same TOC settings as the title in chapter context. To remove the subtitle from the TOC, invoke the Customize Table of Contents dialog box for the relevant table of contents format object and make the necessary changes. See Customize Table of Contents Dialog Box for information.