[xsl] Shallow (in-place) parent-child swap

Subject: [xsl] Shallow (in-place) parent-child swap
From: "David Z. Hirtle" <david.hirtle@xxxxxxxxx>
Date: Mon, 11 Dec 2006 04:55:47 -0500
Greetings all,

I have a significant amount of experience with XSLT but I'm struggling
to find a way to accomplish the following:

<sentence>
 <w>...</w>
 ...
 <w>
   <phr>
     <seg>word</seg>
   </phr>
 </w>
 ...
 <w>...</w>
</sentence>

==>

<sentence>
 <w>...</w>
 ...
 <phr>
   <w>
     <seg>word</seg>
   </w>
 </phr>
 ...
 <w>...</w>
</sentence>

(Singleton phrases are erroneously getting nested within words... This
occurs here and there throughout a large body of marked-up text.)

Note that the order of the <w> elements is significant (words within a
sentence), and that all of the above elements may or may not have
attributes.

I've tried various approaches, but I'm stumped as to how to copy the
<phr> (without its children/text) and then get the <w> copied within.
Perhaps I'm overlooking the obvious here...

I've found similar questions on the list, but the requirements were a
little different and I can't seem to adapt the solutions to this case.

Thanks in advance for any help,

David

Current Thread