Yves Forkl wrote:
> In my configuration I have defined two macro commands, let's call them c1 and
> c2. c2 calls c1 and then performs further steps, depending on the result of
> running c1.
>
> c1 is testing for a condition and executes either sequence c1-a or sequence
> c1-b, those two being included in a <choice> statement.
>
> In case of c1-a, c2 should continue executing. However, in the case of c1-b,
> c2 should stop (or do something different).
>
> Now my question is: What is the preferred way to have c1 pass a kind of
> return value to c2 and to have c2 check for that value?
>
> I am successfully using <pass parameter="c1-b"> at the end of sequence c1-b
> and receiving that value in %_ in c2 just after having called c1. But I
> wonder how to test for it, because XXE's macro language only seems to offer
> XPath-based tests.
>
> Or maybe I have missed another, much simpler way to do what I want (except
> code redundancy :-) ).
>
XPath is a full-fledged expression language which can be used for tasks
which do not involve nodes. For example, compare the value of a variable
to a string. See below.
Yves Forkl wrote:
>> Please provide us with a set of working macro-commands (even if these
>> are just mockups calling alert and/or containing comments), so we can
>> modify them in order to answer your question.
>
> Sorry for not having them set up in the beginning. Here they are as fully
> functional mockups; the condition I am testing for is whether caret is NOT
> within the first<listitem> sibling:
>
> <command name="c1">
> <macro>
> <sequence>
> <command name="selectNode"
> parameter="ancestorOrSelf[implicitElement] listitem" />
> <choice>
> <sequence>
> <test context="$selected"
> expression="boolean(preceding-sibling::*)"/>
> <command name="alert" parameter="c1-a"/>
> <command name="pass" parameter="c1-a"/>
> </sequence>
> <sequence>
> <command name="alert" parameter="c1-b"/>
> <command name="pass" parameter="c1-b"/>
> </sequence>
> </choice>
> </sequence>
> </macro>
> </command>
>
> <command name="c2">
> <macro>
> <sequence>
> <command name="c1"/>
> <command name="alert" parameter="'Result of c1: %_'"/>
> <!-- This is where to switch based on the result of c1 -->
> <command name="alert" parameter="Remainder of c2"/>
> </sequence>
> </macro>
> </command>
<command name="c1">
<macro>
<sequence>
<command name="selectNode"
parameter="ancestorOrSelf[implicitElement] listitem" />
<choice>
<sequence>
<test context="$selected"
expression="boolean(preceding-sibling::*)"/>
<command name="pass" parameter="c1-a"/>
</sequence>
<command name="pass" parameter="c1-b"/>
</choice>
</sequence>
</macro>
</command>
<command name="c2">
<macro>
<sequence>
<command name="c1"/>
<!-- This <set> is not really needed.
However it makes sure that the <test> below will work fine
even if the result of c1 contains quotes. -->
<set variable="resultOfC1" expression="%_" plainString="true" />
<choice>
<sequence>
<test expression="$resultOfC1 = 'c1-b'"/>
<command name="alert" parameter="INSIDE FIRST LISTEM!"/>
</sequence>
<command name="alert" parameter="Outside first listem."/>
</choice>
</sequence>
</macro>
</command>
<binding>
<keyPressed code="F4" />
<command name="c2" />
</binding>
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support