On 06/23/2011 10:43 AM, Philippe Nobili wrote:
>
> Unless we have missed something, we seem to experience an undesirable
> interaction between template definition and putAttribute (in our case)
> function. This is what happens:
>
> 1. We have a template for one of our element, auxbuf:
>
> <cfg:elementTemplate name="auxbuf" selectable="override">
> <auxbuf xmlns="http://www.cggveritas.com/geovation/module/2.0"
> type="Output" number="???" id="???">
> <nativeDescript name="">
> <shorthelp/>
> </nativeDescript>
> <code/>
> </auxbuf>
> </cfg:elementTemplate>
>
>
> 2. We have defined a macro to insert an 'auxbuf' element at various
> places; in this macro, we provide the @type
> attribute as a parameter (%1). Below is an excerpt of this macro: (NB:
> 'insert.jxmo2' simply calls 'insert' and assigns an
> unique, valid ID to the inserted element).
>
> <cfg:command name="insert.auxbuf">
> <cfg:macro trace="true">
> <cfg:sequence>
> <cfg:pass>
> <cfg:command name="insert.jxmod2"
> parameter="%0
> {http://www.cggveritas.com/geovation/module/2.0}auxbuf"/>
> </cfg:pass>
> <cfg:command name="insert.jxmod2"
> parameter="%0
> {http://www.cggveritas.com/geovation/module/2.0}auxbuf"/>
> <cfg:set variable="implicitElement" expression="$selectedElement"/>
> <cfg:command name="putAttribute" parameter="[implicitElement] type %1"/>
>
> <!-- Skipped ..... -->
> </cfg:sequence>
> </cfg:macro>
> </cfg:command>
Replacing:
<cfg:set variable="implicitElement" expression="$selectedElement"/>
<cfg:command name="putAttribute" parameter="[implicitElement] type %1"/>
by just:
<cfg:command name="putAttribute" parameter="type %1"/>
would make the macro simpler. This works because a newly inserted
element is always explicitly selected.
>
> When when execute this macro with %1 set to 'Output' (one of the two
> possible values for this mandatory
> attribute, the other being 'Input'), we get the following error reported
> (when the trace is ON):
>
> -->insert.auxbuf:command: checking...
> putAttribute "type Output"
> <--insert.auxbuf:command: CANNOT EXECUTE
>
> Meaning that 'Output' would not be a legal value for this attribute,
> which is wrong.
>
> 3. When we comment out our template's definition, the macro works as
> expected again:
>
> -->insert.auxbuf:command: checking...
> putAttribute "type Output"
> <--insert.auxbuf:command: can execute
>
> The same macro works fine when 'Input' is passed instead of 'Output';
> did we miss something here ?
In fact, this has nothing to do with your element template, it's related
to the way putAttribute has been implemented.
If an element already has attribute foo="bar", then command
"putAttribute foo bar" cannot be executed (I mean, simply because the
element already has attribute foo="bar").
I agree that this is not intuitive, but I currently do not see whether
the current behavior is useful or not.
The workaround is to rewrite your macro as follows (not tested, but
you'll get the idea):
<cfg:command name="insert.auxbuf">
<cfg:macro trace="true">
<cfg:sequence>
<cfg:pass>
<cfg:command name="insert.jxmod2"
parameter="%0
{http://www.cggveritas.com/geovation/module/2.0}auxbuf"/>
</cfg:pass>
<cfg:command name="insert.jxmod2"
parameter="%0
{http://www.cggveritas.com/geovation/module/2.0}auxbuf"/>
<cfg:choice>
<cfg:test context="$selectedElement" expression="@type = '%1'"/>
<cfg:command name="putAttribute" parameter="type %1"/>
</cfg:choice>
<!-- Skipped ..... -->
</cfg:sequence>
</cfg:macro>
</cfg:command>
Reference:
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support