The follow command
Syntax:
follow expression with queryAfter each node N selected by the expression, the query is evaluated (with N as the context item), and its result is inserted as an immediate following sibling of N. Both the expression and the query must return nodes that are capable of having siblings: that is, element, text, comment, or processing instruction nodes. But if the query returns an atomic value, it is treated as a text node with the same string value.
The result of the operation can be inspected using the command show.
Examples
The command:
follow //img with <caption/>inserts an empty <caption/>
element
after every img
element in the document.
Given a source document:
<cities> <city name="Berlin" country="DE"/> <city name="Paris" country="FR"/> <city name="Rome" country="IT"/> </cities>The command:
follow //city[@name='Paris'] with <city name="Lyon" country="{@country}"/>produces the document:
<cities> <city name="Berlin" country="DE"/> <city name="Paris" country="FR"/> <city name="Lyon" country="FR"/> <city name="Rome" country="IT"/> </cities>