Here's what happens:

* Unless you use RELAX NG grammars forbidding to do so, it is always
legal to delete a text node, whether empty or not.

* Therefore, the text node is always succesfully deleted by
<command name="delete" parameter="[implicitNode]"/>

* Just after the text node has been deleted, *if* *the* *parent*
*element* *becomes* *totally* *empty*, an empty text node is
automatically created by XXE.

That is, you think the text node has not been deleted but it has been
deleted and a new empty text node has been automatically inserted. Note
that all this is driven by the grammar constraining the document.

Rationale for this behavior:
  ** A totally empty element is invisible in the styled view (or is
represented by a hard-to-understand large ink blob).
  ** An empty text node is a handy placeholder for typed text.



Mark Fletcher wrote:
> I'd like my users to be able to use Del to delete empty text nodes and
> empty elements without having to explicitly select them. I've got a
> command that does what I want if the empty text node is not required.
> But it doesn't seem to be able to detect if the text node cannot legally
> be deleted. Any suggestions?
>  
> Here's my code:
>  
> 
> <command name="smartDelete">
> 
> <macro>
> 
> <sequence>
> 
> <choice>
> 
> <sequence>
> 
> <!-- delete selection, if there is one -->
> 
> <pass><command name="delete"/></pass>
> 
> <command name="delete"/>
> 
> </sequence>
> 
> <sequence>
> 
> <!-- check for empty text node -->
> 
> <test expression="normalize-space(.)=''" context="$implicitNode"/>
> 
> <choice>
> 
> <sequence>
> 
> <!-- delete the empty text node, if possible -->
> 
> <pass><command name="delete" parameter="[implicitNode]"/></pass>
> 
> <command name="delete" parameter="[implicitNode]"/>
> 
> </sequence>
> 
> <sequence>
> 
> <!-- if not possible to remove text node, select text node and ask user
> if they'd like to convert it to another element or delete the parent
> element altogether.
> 
> ** the macro never gets to this point, because the previous sequence
> always passes, even when the text node has not been deleted **
> 
> -->
> 
> <!-- haven't written this code yet .... -->
> 
> </sequence>
> 
> </choice>
> 
> </sequence>
> 
> <sequence>
> 
> <!-- not an empty text node, do normal deleteChar -->
> 
> <pass><command name="deleteChar"/></pass>
> 
> <command name="deleteChar"/>
> 
> </sequence>
> 
> </choice>
> 
> </sequence>
> 
> </macro>
> 
> </command>

Reply via email to