9. Variables mapped to the selection in XXE

The following macro can be used to move a DocBook list item (listitem, callout or step) down in the list. How to move a DocBook list item up in the list can be found in Example 4.5, “Using the XPath-based constructs match and set”.

<command name="moveListItemDown">
  <macro undoable="true" label="Move List Item Down">
      <command name="selectNode" 
        parameter="ancestorOrSelf[implicitElement] listitem callout step" />1
      <match context="$selected" pattern="*[position() &lt; last()]" />2
      <set variable="anchor" context="$selected" 
           expression="./following-sibling::*[1]" />3
      <command name="cut" />4
      <set variable="selected" expression="$anchor" />5
      <command name="paste" parameter="after" />6


This step ensures that the macro can be executed only inside a list item.


This step ensures that the macro cannot be executed for last list item.

It uses the XPath-based construct match. As a pseudo-command of a macro, it can be executed only if the context node specified in its context attribute matches the XSLT pattern specified in its pattern attribute.

This construct like pass, fail and test, is only a test. When match is actually executed, it does nothing at all.


This step saves in user variable named anchor, the list item which follows the selected list item.

Variable selected referenced from the context attribute of this set construct is, like implicitElement seen in previous example, one of the many predefined variables mapped to the selection in XXE:

  • Reading variable selected returns the node, first selected in the node selection, whatever is its type.

  • Writing variable selected clears current node selection or current text selection if any, and then, explicitly selects specified value (which must be a node set).


Cut selected list item.


Select the list item saved in variable anchor: ``the following one''.

The selection is changed by assigning a node value to predefined variable selected, as explained above.


Paste the list item found in the clipboard after last selected list item.