Jeff Hooker wrote:
>
> What the command below does it pretty obvious to you, I'm sure.
Not really.
<command name="xpathSearch"
parameter="//ns:signal/ns:state[last()]"/>
is not easy to understand given what you want to do.
> What's not obvious to me is how to recurse the command so that rather than
> just adding a new "state" element to the first "signal" element, it adds a
> new "state" element to every "signal" element in the document.
>
> There's no easy way of doing this, is there?
>
>
> <commandname="insertStateNames">
> <macroundoable="true"repeatable="true">
> <sequence>
> <getexpression="join(//pmc:testComponent/pmc:states/pmc:state/@name, '
> ')"/>
> <commandname="pick"
> parameter="'Choose state:' false %_"/>
> <setvariable="attvalue"expression="%_"plainString="true"/>
> <commandname="xpathSearch"parameter="//ns:signal/ns:state[last()]"/>
> <commandname="insertNode"parameter="sameElementAfter[implicitElement]"/>
> <getexpression="$attvalue"/>
> <commandname="putAttribute"parameter="name '%_'" />
> </sequence>
> </macro>
> </command>
>
>
Personally, I never write recursive macro-commands. When a macro seems
to be too advanced, I prefer to write it in Java.
Note that I didn't know that it was possible to write recursive macros
before a user informed me about this feature a few years ago.
Now, this being said, it's difficult to help you without rewriting this
macro myself, which is not possible in the context of this mailing list.
I would say that:
[1] You need to separate your macro in 2 parts.
First one lets the user pick a state and selects the first signal
element of the document.
Second one [a] adds a state child element after the last state child
element (if any) of selected signal element, [b] selects next signal
element and then [c] recurses.
Note that you can pass $attvalue as a %0 parameter to the second macro.
[2] In the second, recursive, macro, I would use something like (not
sure, because I don't know the structure of your document)
<set variable="selectedElement"
context="$selected"
expression="following::pmc:signal"/>
to select next signal element.
See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_vars.html
Instead, it's also possible to use command selectNode (more efficient;
does not support namespace prefixes: use Clark's notation for qualified
names).
See
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/selectNode.html