John L. Clark wrote:
> In the spirit of the simpara example in the poweruser documentation, I
> am trying to apply an xslt sheet to sections of a document, replacing
> the corresponding section of the original with the translated section.
> I'm extending the DocBook configuration, so all of these operations
> apply to DocBook files. The command that seems to be buggy is the
> docbook.specifyChangesOwner command. When I select any element other
> than the document root, the macro runs correctly, the translation
> occurs as expected, and I eventually see the "After paste..." alert.
> That works. However, when I select the document root (in my
> experiments, the article element) and try to run the command, the
> translation does not occur and the macro never gets to the "After
> paste..." alert. Am I missing something? Is there some validity
> constraint I'm overlooking? I've attached a zip file of the
> configuration file and the xslt sheet for your convenience.
You cannot replace the root element. Try to do this using the GUI and
you'll see that all the editing commands are disabled when the root
element is selected.
Why? Because XXE is not a document editor. XXE is just a root element
editor. That is, with XXE, you can just change the content of the root
element.
> Strangely enough, when I uncomment the first alert, the macro never gets
> to the second alert, and the whole macro no longer works in any case.
---
<cfg:command name="docbook.addOwnershipCondition">
<cfg:process>
<cfg:copyDocument selection="true" to="in.xml"/>
<cfg:transform file="in.xml" stylesheet="xsl/ownChanges.xsl"
to="out.xml">
<cfg:parameter name="address">%0</cfg:parameter>
</cfg:transform>
<cfg:read file="out.xml"/>
</cfg:process>
</cfg:command>
<cfg:command name="docbook.noteChangesOwner">
<cfg:macro>
<cfg:sequence>
<cfg:command name="selectNode" parameter="self"/>
<cfg:command name="docbook.addOwnershipCondition"
parameter="'%0'" />
<!--<cfg:command name="alert" parameter="Before paste..."/>-->
<cfg:command name="paste" parameter="to %_"/>
<cfg:command name="alert" parameter="After paste..."/>
</cfg:sequence>
</cfg:macro>
</cfg:command>
---
Macro "docbook.addOwnershipCondition" returns a value. This value is
passed to command "paste" using the '%_' variable.
If you uncomment the first "alert", the '%_' is replaced by the value of
command "alert." But command "alert" does not return any value.
Therefore '%_' is not expanded and "paste" cannot be executed (that
is, "paste" refuses to insert an element named "%_").
The semantics of '%_' is "the result of last executed command"; not "the
result returned by last executed command returning a value".
If last executed command does not return a value, %_ is simply cleared.
> While I'm on the topic, I would like to ask another question. Is there
> any command which will select an arbitrary section of the document (in
> particular, I want to be able to select the root)? I tried the get
> command, but that apparently only gets textual content. The various
> selectNode commands are useful only with respect to the current node,
> and not for general purpose selection.
V2.6 (not before February 2006) should have macro-commands on stero?ds.
They'll support what you need and much more.
Don't worry, macro-commands you write today will be *fully compatible*
with these future macro-commands (because conceptually there is no
change at all).