On 11/29/2011 11:28 AM, Yves Forkl wrote: > > Following your excellent advice, I came up with two pieces which go halfway > each, but which I still need to connect to each other. Generating nodes in > XXE's clipboard format with XSLT works fine, and replacing the selected root > element child nodes with clipboard content seems to be OK, too. > > I only don't manage yet to take over the XSLT output, i.e. get it into the > macro variable %_ for pasting. Currently, I have these two commands and > wonder how to properly "connect" them (is this only possible when using the > transform as a macro command?): > > <command name="mytransform_internal"> > <process showProgress="false"> > <copyDocument to="TMP_in.xml" /> > <transform stylesheet="mytransform.xsl" > version="2.0" > file="TMP_in.xml" to="TMP_out.xml" /> > <read file="TMP_out.xml" encoding="UTF-8" /> > </process> > </command>
The above process command returns the result of <read>, that is, the document generated by mytransform.xsl, serialized as a string. > > <command name="mytransform"> > <macro> > <sequence> > <command name="mytransform_internal"/> > <!-- how to put the results into %_ here? --> A process command is a normal command. And the result returned a command of any type is always available in the "%_" variable. Therefore there is nothing special to do. > <set variable="rootContents" > expression="%_" plainString="true"/> > <set variable="selected" expression="/*" /> > <command name="selectNodes" parameter="children" /> > <get expression="$rootContents" /> > <command name="paste" parameter="to %_" /> > </sequence> > </macro> > </command> > > What am I missing here? > Well, I don't know. I just see a little mistake in the above macro: --- <set variable="selected" expression="/*" /> <command name="selectNodes" parameter="children" /> --- should be replaced by: --- <set variable="selectedNodes" expression="/*/node()" /> --- The name of the variable is "selectedNodes" and not "selectNodes". See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_vars.html --> Just to be 100% sure this time, the following commands: --- <command name="mytransform_internal"> <process showProgress="false"> <copyDocument to="TMP_in.xml" /> <transform stylesheet="mytransform.xsl" version="1.0" file="TMP_in.xml" to="TMP_out.xml" /> <read file="TMP_out.xml" encoding="UTF-8" /> </process> </command> <command name="mytransform"> <macro trace="true"> <sequence> <command name="mytransform_internal"/> <set variable="rootContents" expression="%_" plainString="true"/> <set variable="selectedNodes" expression="/*/node()" /> <get expression="$rootContents" /> <command name="paste" parameter="to %_" /> </sequence> </macro> </command> <binding> <keyPressed code="F5" /> <command name="mytransform" /> </binding> --- where mytransform.xsl is: --- <xsl:stylesheet version="1.0" xmlns="" xmlns:c="http://www.xmlmind.com/xmleditor/namespace/clipboard" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/*"> <c:clipboard> <xsl:apply-templates/> </c:clipboard> </xsl:template> <xsl:template match="para"> <formalpara> <xsl:for-each select="@*"> <xsl:copy/> </xsl:for-each> <title></title> <para> <xsl:apply-templates select="node()"/> </para> </formalpara> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> --- work as expected when applied for example to a_section.xml: --- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> <section> <title>A section</title> <para>Paragraph "<emphasis role="bold">#1</emphasis>".</para> <para>& Paragraph "<emphasis role="bold">#2</emphasis>".</para> <para>& Paragraph "<emphasis role="bold">#3</emphasis>".</para> </section> --- -- XMLmind XML Editor Support List [email protected] http://www.xmlmind.com/mailman/listinfo/xmleditor-support

