On 07/14/2014 06:04 PM, Fabián Mandelbaum wrote:

I'm trying to write a macro command to remove all elements matching a
given XPath expression using XXE 5.9.0.

This is the command definition in my customization file (0docbook5.xxe):

  <command name="db5.removeUnusedParts">

     <macro repetable="true" undoable="true" label="Remove Unused Parts">

         <sequence>

             <command name="xpathSearch"
parameter="//*[@revisionflag='off']" />

             <command name="delete" />

         </sequence>

     </macro>

   </command>



I assign it to a button on the UI

<button toolTip="Remove Unused Parts"

             icon="../config/common/icons/up.png">

         <command name="db5.removeUnusedParts" />

     </button>



The button shows up and it is enabled when I select an element in the
document. Clicking the button removes only the first matching node from
the XPath node-set result.

So, a few questions:

1) How can I have the button always enabled as opposed to enabled only
when selecting an element? The idea is to actually make this not a
button, but a menu entry of the "DocBook" (XML) menu.

Start the sequence with command "pass". See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/pass.html




2) If xpathSearch returns a node-set, why isn't the delete command
applied to all nodes in the node-set and it's only applied to the first
matching node?

The xpathSearch command does not return a node-set. It has been designed to implement "Search|Find Element", which selects first found node matching an XPath expression. See http://www.xmlmind.com/xmleditor/_distrib/doc/help/com.xmlmind.xmledit.cmd.xsearch.XPathSearchDialog.html

The xpathSearch command is not really intended to be used in macros. It's simpler and cleaner to use <set variable="selectedElement" expression="..." />. See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html . See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_vars.html .




How can I 'loop' through all nodes returned in the
node-set applying the delete command on them?

Write a recursive macro-command. Not recommended though. See below.




 Will I have to forget
about this macro command and write a custom Java command instead (Not
that I do not know how to do it, I'm just trying to solve this with what
XXE already has)?

Yes, when a macro-command becomes too complicated, it's always best to rewrite it in Java.




All of the examples I've found on the documentation apply commands to a
single node, not to a node-set. I've searched the docs too and found no
"loop-like" construct to write commands (I'm pretty sure there's good
reasons for that... but I need one :-))


It's a design choice. Macro-commands were first designed to be very simple. We have progressively made them more complex to increase their power. May be macro-commands are now too sophisticated for their intended use.

For now, we are reluctant to make them even more complex by adding functions, for-loops, if/elseif/else, etc (though we have already these ``XPath++ constructs'' somewhere else; they are used to implement "Paste From Word").

We are also reluctant to add JavaScript support to XMLmind XML Editor because we fear that this would lead to a flurry of support requests.


--
XMLmind XML Editor Support List
xmleditor-support@xmlmind.com
http://www.xmlmind.com/mailman/listinfo/xmleditor-support

Reply via email to