9. Variables mapped to the selection in XXE
Prev | Chapter 2. Writing macro-commands | Next

## 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 "Using the XPath-based constructs match and set".

      <command name="moveListItemDown">
        <macro>
          <sequence>
            <command name="selectNode"
              parameter="ancestorOrSelf[implicitElement] listitem callout step" />
            <match context="$selected" pattern="*[position() &lt; last()]" />
            <set variable="anchor" context="$selected"
                 expression="./following-sibling::*[1]" />
            <command name="cut" />
            <set variable="selected" expression="$anchor" />
            <command name="paste" parameter="after" />
          </sequence>
        </macro>
      </command>

| 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.

Prev | Up | Next
8. General use of get | Home | 10. Contextual commands