Nadia,
While you are trying to apply David's solution I'd recommend you also test 
XMetaL to see whether the assumption he makes in his code (the PI pairs are 
"well-balanced" with respect to element markup) is correct, or whether 
XMetaL cannot in fact insert such a PI wherever it likes, thereby breaking 
the implicit "containment" and presenting, in effect, an overlap problem. 
(The "virtual" elements demarcated by the PI-pairs overlap the XML's own 
element structures.)
While I haven't myself tested XMetaL for this, I fear and suspect this is 
the case.
Overlap problems are notoriously hard for XML technologies in general, and 
there is a considerable (and growing) literature on the topic. It's 
sometimes referred to as "multiple concurrent hierarchies". The various 
approaches to dealing with this vary quite a bit depending on the actual 
processing requirements for the system (e.g. projects that work with stable 
and complete datasets can do things very differently from systems that have 
to deal with new data all the time), and include proposals to step outside 
XML altogether. This is because, better than any other example I can think 
of in XML tech, they demonstrate the engineering principle (or Cosmic Law 
of Compensation, if you prefer) that where there's a gain, there's a loss. 
In this case, XML's clumsiness at dealing with this (or more precisely, 
XSLT's) is a consequence of our establishing the tree as our data model of 
choice.
Keywords you might Google:
SGML CONCUR
markup overlap
multiple concurrent hierarchies
TexMECS
JITTS
LMNL
Cheers,
Wendell
======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================