On 08/10/2010 04:23 PM, Yves Forkl wrote:
>
> I am asking for help with a macro command. The macro needs to work on a
> sequence of nodes - either the nodes which the user has explicitly selected
> or,
> if there is no explicit selection, the current element together with all of
> its
> siblings.
>
> How to test for the existence of a selection and create it if it is missing?
> (I
> suppose by testing if $selectedNode equals the empty set, but I can't
> remember
> the pattern.)
>
Here it is:
---
<command name="ensureNodesAreSelected">
<macro>
<choice>
<test expression="$selectedNodes"/>
<set variable="selectedNodes"
context="$implicitElement" expression="../node()"/>
</choice>
</macro>
</command>
<binding>
<keyPressed code="F4" />
<command name="ensureNodesAreSelected" />
</binding>
---
If you want the above macro to work even when there is a *text*
selection, specify:
---
<command name="ensureNodesAreSelected">
<macro>
<choice>
<test expression="$selectedNodes"/>
<sequence>
<command name="cancelSelection"/>
<set variable="selectedNodes"
context="$implicitElement" expression="../node()"/>
</sequence>
</choice>
</macro>
</command>
---
(cancelSelection is used to discard the text selection, if any.)
References:
*
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html
*
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/cancelSelection.html
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support