Den 9. apr. 2010 kl. 13.18 skrev Hussein Shafie:

>> Combined with some macro commands it should be possible to get the attribute 
>> value of the preceeding sibling (the old element), and add the attribute 
>> with the specified value to the current element. But I'm unable to see how 
>> to tie these things together, and I could find no examples of using that 
>> java command.
>> 
>> Could you give me some hints on how to proceed?
> 
> There is no way to do this by simply recording a macro. You need to
> write the macro by hand and use in it:
> 
> * The (XPath-based) <get> child element of <macro> to obtain the value
> of the attribute.
> 
> See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_get.html
> 
> *  The (XPath-based) <set> child element of <macro> to save the value of
> the attribute in a variable.
> 
> * Command putAttribute to set the attribute on the newly created element.
> 
> See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/putAttribute.html

Thanks for the suggestions - that solved it. The complete macro I ended up with 
looks like the following (posted here in case it could be useful for others 
searching through the archives) - it will cut the selection, insert a new 
element after the current one, paste in the selection just cut out, and finally 
copy one attribute to the new element:

  <cfg:command name="dvgt.convertToTranslation">
    <cfg:macro>
      <cfg:sequence>
        <cfg:command name="cut" parameter="[implicitElement]"/>
        <cfg:command name="insert" parameter="after[implicitElement] t"/>
        <cfg:command name="cancelSelection"/>
        <cfg:command name="paste" parameter="toOrInto"/>

        <cfg:get context="$implicitElement/preceding-sibling::*/@pos" 
expression="."/>
        <cfg:set variable="POS" expression="%_" plainString="true" />

        <cfg:get expression="$POS" />
        <cfg:command name="putAttribute" parameter="[implicitElement] pos %_" />

      </cfg:sequence>
    </cfg:macro>
  </cfg:command>


Best regards,
Sjur Moshagen

 
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support

Reply via email to