![]() |
| Previous Top Next |
Global Templates |
A global template is defined for a global element or a global type (globally defined XML Schema components are children of the xs:schema element). A global template specifies instructions for the selected schema element or global type, and it is invoked by a call from the main template. The processing model is similar to that of declarative programming languages, in that a single template is defined and invoked multiple times. In this way a single definition can be re-used multiple times. Global templates are invoked in two situations:
| • | When an element or type in the main template has been set to reference its global template (done by right-clicking and selecting Make Global Template). |
| • | When a (rest-of-contents) is inserted within an element or type in a local template, and the rest of the contents of that element/type are includes an element or type for which a global template exists. |
Global templates are useful if an element (or type) occurs within various elements or in various locations, and a single set of instructions is required for all occurrences. For example, assume that a para element must be formatted the same no matter whether it occurs in a chapter, section, appendix, or blockquote element. An effective approach would be to define a global template for para and then ensure, that in the main template the global template for the para element is processed wherever required (for example, by including //chapter/para in the main template and specifying that para reference its global template; or by including //chapter/title and then including (rest-of-contents)). So also, a global template can be defined for a complex type (for example, one that defines an address model) or even for a simple type (for example, xs:decimal). In such cases, all occurrences of the type (complex or simple) that invoke the global template for that type will be processed according to the rules in the global template.
Creating a global template
Global templates can be created for global elements and global types, and are created from the Schema Tree sidebar (screenshot below).

In the Schema Tree sidebar, global components (elements and types) are listed under the following headings:
| • | Global elements under the All Global Elements heading |
| • | Global types under the Global Types heading (these are the global types in the schema of the active document) |
| • | Global types under the All Global Types heading (these are the global types in the schema of the active document plus the built-in types of XML Schema) |
To create a global component (element or type) as a global template, right-click the global component and select the command Make/Remove Global Template. The template will be created and appended to the already existing templates in Design View.
Global templates can also be created from templates in the main template if these templates are for global components (global elements or global types). To create a template in the main template as a global template, right-click the template (either in Design View or the Schema Source sidebar) and select the command Make Global Template. A global template is created from the selected template (it is appended to the templates in Design View) and the template in the main template is automatically defined to use this global template.
Using a global template
After a global template has been created, it can be used by another template having the same qualified name. When a global template is used, its processing instructions are called and used by the local template at runtime. To use a global template for a local template, right-click the local template in Design View and select the command Use Global Template.
Copying a global template locally
After a global template has been created, its processing instructions can be copied directly to a template of the same qualified name in the main template. To do this, right-click the local template and select the command Copy Global Template Locally. Copying the global template locally is different than using the global template (at runtime) in that the processing instructions are merely copied in a one-time action. The global template has no further influence on the local template. Either, or both, the global template and local template can subsequently be modified independently of each other, without affecting the other. On the other hand, if it is specified that a global template should be used (at runtime) by a local template, then any modifications to the global template will be reflected in the local template at runtime.
Removing a global template
To remove a global template, right-click the global template to be removed, either in Design View or the Schema Tree sidebar, and select the command Make/Remove Global Template.
Simple global templates and complex global templates
Global templates are of two types: simple and complex. Complex global templates are available for reasons of backward-compatibility. If a global template in an SPS created with a version of StyleVision prior to version 2006 contains a table or list, then that global template will typically be opened in StyleVision 2006 and later versions as a complex global template.
A complex global template is different than a simple global template in the way the node for which the global template was created is processed. When the first instance of the node is encountered in the document, the complex global template processes all subsequent instances of that node immediately afterwards. A simple global template, on the other hand, processes each node instance only when that node instance is individually encountered.
It is important to note that a simple global template will be automatically converted to a complex global template if a predefined format or newline is created around the element node for which the global template was created. This will result in the processing behaviour for complex global templates (described in the previous list item). To revert to the simple global template, the predefined format should be removed (by dragging the node outside the predefined format and then deleting the predefined format), or the newline should be removed (by deleting the item in the Design Tree sidebar), as the case may be. To avoid the automatic conversion from simple global template to complex global template, make sure that the predefined format or newline is added within the node tags of the element for which the simple global template was created.
Global templates in modular SPSs
When an SPS module is added to another SPS module, the global templates in the added module are available for use within the referring SPS. For more information about using modular SPSs, see the section Modular SPSs.
See also:
Inserting XML Content as Text, for a description of how to insert XML node content in the design.
Rest-of-Contents, for information about using the (rest-of-contents) placeholder to specify processing of other content.
Main Template, for a description of the main template and how it is to be used.
Design Fragments, for a description of how Design Fragments are to be used.
Template Filters, for a description of how to use template display filters.
Modular SPSs, for information about using modular SPSs.
|