On 02/14/2012 10:55 AM, Yves Forkl wrote: > > I would like to enable my users to perform a series of automated string > substitutions, by providing them with a macro that they will have to run. > > The substitution table is to be kept in a kind of configuration file > (preferably XML) so that it may be easily modified. I think I should use the > document() function together with the<get> macro function to slurp it into > my macro, inspired a bit by this example: > http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_examples.html#insertFromOtherDoc_example > > Now I am only wondering which would be the best way to process the > substitution table: > > a) Write a recursive macro that calls replaceText for each remaining > substitution > > b) Transform the whole document and repeatedly apply the XPath replace() > function to each text node > > Which is your advice? (Performance aspects don't come in for much in this > case.) >
This kind of command is very easy to write in Java and not easy at all to write as a macro. I would do this (I'm not used to write recursive macros): * Write a macro (marked as being undo-able) which invokes an ancillary process-command. This process-command would have showProgress="false" and its transform child element cacheStylesheet="true" See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro.html See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/process.html * The process-command transforms the whole document and generates an XML file containing the child nodes of the root element using XXE's clipboard format. Example: if the root document is: <root> <a>AAA</a> <b>BBB</b> <c>CCC</b> </root> the process-command could generate: <ns:clipboard xmlns:ns="http://www.xmlmind.com/xmleditor/namespace/clipboard"> <a>111</a> <b>222</b> <c>333</b> </ns:clipboard> * The process-command ends with a <read> which returns the contents of the transformed document. See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/read.html * The macro-command stores this returned contents in a variable for later use. Let's call this variable newContents. * The macro-command selects all the child nodes of the root element of the document being edited. * The macro-command pastes the value of variable newContents in order to replace all the child nodes of the root element of the document being edited. See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_get.html See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/paste.html --- PS: Note that *may* *be* you could embed an XSLT stylesheet inside the macro-command rather than the ancillary process-command. This would be more efficient and slightly more elegant. See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html : <transform source = string> XSLT 1 or XSLT 2 stylesheet or transform element </transform> -- XMLmind XML Editor Support List [email protected] http://www.xmlmind.com/mailman/listinfo/xmleditor-support

