Context Sensitivity and Insertion Position of Custom Content

Suppose you want to insert images by means of custom content. Let's suggest that your schema requires the inlinegraphic element for an image within text, while when in the section element, it requires the figure element with a child called graphic.

It is possible to specify several templates for different contexts of your document. The context is specified as XSLT Match Pattern in the If matches edit box. For each additional context you must create a separate tab in the Custom Content Dialog, specify a specific context match expression, and the content template for this content.

By default the content template will be inserted into the current cursor position. However, it may be inserted into another position relative to the current cursor position. This different position may be specified with XPath Expression in the Node: text box and the Position: combo-box.

See example Creating a Context-Sensitive Image Insertion Command.

You can specify any number of alternative content templates. Every context, starting from the first, is tested against the Context match expression. If the expression evaluates to true in the current context, or if there is no match expression ( If matches field is empty), then the Content will be inserted.

See example Inserting Custom Content to a Position that is Different from the Current Cursor Position.

Creating a Context-Sensitive Image Insertion Command

For creating a custom content described in the first paragraph of this section, do the following:

Inserting Custom Content to a Position that is Different from the Current Cursor Position

Sometimes you need to insert a content into a position which is different from the current cursor position. For example, usually you want to insert a new paragraph below the current paragraph, despite the fact that the cursor may be currently located within text or an emphasis element within the paragraph.

For this case you should specify the relative position where the inserted content should go. See the figure below:



In this example, the Position is after , and the Node is

ancestor-or-self::para[1]

This means that the para will be inserted not into the current cursor position, but after "the first para node among all the ancestors of the current node, including the node itself". For example, if the cursor is within an emphasis of a para, the para will be found, and after it the new para will be inserted.