When the action is triggered, the following happens:
1.The nodeset specified by the Subnode(s) XPath expression is deleted from the target node (specified in the Target Node setting), if it exists there.
2.The nodeset specified by the Subnode(s) XPath expression is copied from a source node (specified in the Parent of source node(s) setting) to the target node. The nodeset can be appended either as a first child or last child of the target node.
The XPath expression of the Subnode(s) setting is evaluated separately for source and target: in the context, respectively, of the node specified as the source node and the node specified as the target node.
Given below are two examples that demonstrate how the Replace Node(s) action works.
Consider the structure of the two XML trees shown in the Page Sources pane shown below.
•$XML1/ArticleOriginal has a child element named Body.
•$XML2/ArticleCopy has child elements named Header, Intro, and Body, in that order
We can replace the Body element of ArticleCopy with the Body element of ArticleOriginal by using the Replace Node action as shown in the screenshot below.
The action appends a subnode named Body as a last child from a source node named ArticleOriginal to a target named ArticleCopy. The screenshot below shows the page sources during a simulation, after the action has been executed. Notice that the Body element of ArticleCopy has been replaced by the Body element of ArticleOriginal.
Notice that Header and Intro have not been touched, but Body has been replaced. If ArticleCopy had had no Body element, then a new Body element would have been appended.
The XPath expression Body (specified in the Subnode(s) setting) is evaluated in the context of the Source node and Target node XPath expression, respectively, in order to (i) locate the source nodeset to copy, and (ii) locate the node from which to delete and into which to append.
The screenshot below shows the settings required to append an entire nodeset from one (source) node to another (target) node. All the descendant elements of the source node $XML1/office/usa, together with their attributes, are appended to the target node $XML2/offices/office[@id="usa"].
The exact sequence of actions is as follows:
1.The Subnode(s) XPath expression *, @* locates all descendant elements of the target node $XML2/offices/office[@id="usa"], and deletes them.
2.The Subnode(s) XPath expression *, @* locates all descendant elements of the source node $XML1/office/usa, and copies them as a single nodeset body to the target node $XML2/offices/office[@id="usa"]. Since all of the target node's child elements have been deleted, the new subnode will entirely replace the previous descendants of the target node.
MobileTogether provides a range of XPath extension functions that have been specifically created for use in MobileTogether designs. Some functions can be particularly useful with specific actions. For example, mt-available-languages() returns the languages in which the solution is available and could, for example, be used with the Message Box action. If a function is especially relevant to this action, it is listed below. For a full list of extension functions and their descriptions, see the topic MobileTogether Extension Functions.