On 09/17/2014 10:29 PM, maxwell wrote:
On 2014-09-17 03:29, Hussein Shafie wrote:
--> If you need more than this basic function, please write (or
record... a macro-command and then bind it to a keystroke...

This macro-command
(http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro.html)
could consist in:
...
store value of attribute XXX in a variable YYY (<set> child element in
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html#set)


+
insertNode sameElementAfter
+
get value of variable YYY (<get> child element in
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html#get)


+
putAttribute XXX=YYY on newly inserted element
(http://www.xmlmind.com/xmleditor/_distrib/doc/commands/putAttribute.html)


Thanks--this worked.  My code is
--------
    <cfg:pass>
        <cfg:match context="$implicitElement" pattern="ilr:langData"/>
    </cfg:pass>
    <get context="$implicitElement/@script" expression="string(.)"/>
    <set variable="sScript" expression="%_" plainString="true" />
    ...other stuff...
    <command name="insertNode" parameter="sameElementAfter"/>
    <command name="selectNode"
        parameter="descendant[implicitElement]
{http://umd.edu/Interlin}langData"/>
    <get expression="$sScript"/>
    <command name="putAttribute" parameter="[implicitElement] script %_"/>
--------
I was a little surprised in that last step that I couldn't somehow use
$sScript directly, but had to instead do the <get...> <... %_> thing.
And that we need to encode the namespace in the selectNode command by
URI ({http://umd.edu/Interlin}), rather than using a prefix (ilr:) But
it works.

For the sake of simplicity, the vast majority of commands (like putAttribute) are not namespace aware or XPath enabled. (By the way, <match>, <get> and <set> are not commands.)

Note that the following two lines:

---
<get context="$implicitElement/@script" expression="string(.)"/>
<set variable="sScript" expression="%_" plainString="true" />
---

can be combined into a single, strictly equivalent, line:

---
<set variable="sScript" context="$implicitElement/@script"
     expression="string(.)"/>
---



(The <ilr:langData> element is something we borrowed from Andy Black,
who's probably lurking on this mailing list.)



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

Reply via email to