Benoit Maisonny wrote:
>
> I can't find a way for a macro to copy an element from another document
> that the one where the macro was started. I found this thread in the
> archives on this topic:
> http://www.xmlmind.com/pipermail/xmleditor-support/2007-January/004964.html
> But the solution proposed (get) only gets strings from the external
> document, not elements.
>
> My findings:
> - cfg:get only returns string (this is documented).
> - cfg:set does not accept an expression with document() that returns
> nodes from a foreign document (there is an error message if trace is
> enabled).
> - xpathSearch command throws a NullPointerException when document() is
> used.
> - XXE.open opens a doc, gives it the focus, the caret is visible and a
> user could start typing in it, yet $implicitElement and the other
> variables still point to the (now out of focus) initial document.
xpathSearch and XXE.open are of no use in your case.
> So, it looks like the only way to copy nodes from 1 doc to another is
> via the clipboard, but this cannot be done by a macro: there must be a
> user action to change the current document before copying or pasting.
>
> Did I miss anything? Should any of the above method work and so I must
> have made a mistake somewhere?
You missed nothing.
A macro like this one should work fine:
---
<binding>
<keyPressed code="F5" />
<command name="pasteElementFromOtherDoc" parameter="toOrInto" />
</binding>
<property name="templateFile" url="true">VATrates.html</property>
<command name="pasteElementFromOtherDoc">
<macro trace="true">
<sequence>
<command name="prompt"
parameter="Question 'ID of Element to be Pasted'" />
<set variable="elementId" expression="%_" plainString="true" />
<get
expression="serialize(document(system-property('templateFile'))//*...@id=$elementid])"
/>
<command name="paste" parameter="%0 %_" />
</sequence>
</macro>
</command>
---
*Except* that XXE has no serialize() extension function yet. We'll
implement this XPath extension function in next release.
---
PS: The above macro works if you remove serialize(), but in such case,
when the parameter of paste is toOrInto, it is the string value of the
element which is pasted.