1.2. Macro-variables
Prev | 1. Reference | Next

### 1.2. Macro-variables

The parameter of a command `C` contained in the macro-command can contain variables. These variables are substituted with their values before executing command `C`.

Macro-variable substitution is also performed in the `context`, `pattern` and `expression` attributes of the `match`, `test`, `get`, `set` pseudo-commands.

Excerpt of example 2 below: `<command name="putAttribute" parameter="%0 %1"/>`.

Variable | Description
--- | ---
`%0`, `%1`, `%2`, ..., `%9`, `%*` | A macro-command can have a parameter. This string is split like in a command line. First 10 parts of the split parameter can be referenced as variables `%0`, `%1`, `%2`, ..., `%9`. `%*` can be used to reference the whole parameter of the macro-command.
`%D`, `%d` | `%D` is the file name of the document being edited. Example: `C:\novel\chapter1.xml`. This variable is replaced by an empty string if the document being edited is found on a remote HTTP or FTP server. `%d` is the URL of the document being edited. Example: `file:///C:/novel/chapter1.xml`.
`%P`, `%p` | `%P` is the name of the directory containing the document being edited. Example: `C:\novel`. This variable is replaced by an empty string if the document being edited is found on a remote HTTP or FTP server. `%p` is the URL of the directory containing the document being edited. Example: `file:///C:/novel`. Note that this URL does not end with a '`/`'.
`%N`, `%R`, `%E` | %N is the base name of the document being edited. Example: `chapter1.xml`. %R is the base name of the document being edited without the extension, if any (sometimes called the root name). Example: `chapter1`. %E is the extension of the document being edited, if any. Example: `xml`. Note that the extension does not start with a '`.`'.
`%n`, `%r`, `%e` | Similar to `%N`, `%R`, `%E` except that these variables contain properly escaped URI components. For example if `%R` contains "`foo bar`", then `%r` contains "`foo%20bar`".
`%S` | `%S` is the native path component separator of the platform. Example: `'`\`'` on Windows.
%U | User's account name. Example: john.
%H | User's home directory. Example: /home/john.
`%W`, `%w` | `%W` is the name of the user's current working directory. Example: ``/home/john/docs/report22``. `%w` is the URL of the user's current working directory. Example: ``file:/home/john/docs/report22``. Note that this URL does not end with a '`/`'.
`%C`, `%c` | `%C` is the name of the directory containing the XXE configuration file from which the macro command has been loaded. Example: `C:\Program Files\XMLmind_XML_Editor\addon\config\docbook`. `%c` is the URL of the above directory. Example: `file:///C:/Program%20Files/XMLmind_XML_Editor/addon/config/docbook`. Note that this URL does not end with a '`/`'.
`%_` | A macro-command can be used to specify a ``pipe'' of commands. If variable `%_` is referenced in the parameter of command `C` contained in the macro-command, this variable is substituted with the result of the command executed before `C`. Each executed command overwrites `%_`. This variable is set to the empty string for commands which do not return a result.

The "`%`" character can be escaped using "`%%`". The above variables can be specified as `%{0}`, `%{1}`, ..., `%{R}`, `%{E}`, etc, if it helps (see note about escaped URIs).

Prev | Up | Next
1.1. Pass and fail cheat sheet | Home | 1.3. XPath variables