El 05/03/2011 18:42, John L. Clark escribió:
> To whom it may concern:

As you address your post this way ...

> ...
> ...  The
> particular use case that just struck me is fast reordering of
> bibliography entries in DocBook.

In case this helps, here are a couple of macros I wrote sometime ago to 
reorder the explicitly selected element(s) among its/their siblings. You 
can change the key bindings from the suggested alt+ctrl+UP/DOWN to 
whatever you want. They work with single and multiple selections.

(warning: long lines may get wrapped at your end)

-------------------------------------

   <!-- 
=======================================================================
     Move the explicitly selected element(s) before the preceding element

======================================================================== -->

   <command name="moveBefore">
     <macro>
       <sequence>
         <!-- test for a preceding element, and record its location -->
           <match context="$selected" pattern="*[position() &gt; 1]" />
           <set variable="newAnchor" context="$selected"
                expression="./preceding-sibling::*[1]" />
         <!-- copy the selected element(s) and record its location -->
           <command name="copy" parameter="[selectedNodes]" />
           <set variable="anchor" expression="$selectedNodes" />
         <!-- select now the preceding element -->
           <set variable="selected" expression="$newAnchor" />
         <choice>
           <sequence> <!-- try to complete the command -->
             <!-- paste (duplicate) the selection copy before the 
preceding element -->
               <command name="paste" parameter="before" />
             <!-- select the whole set of pasted elements and record its 
location -->
               <set variable="selected2" expression="$newAnchor" />
               <command name="selectNode" 
parameter="extendToPreviousSiblingOrNode" />
               <set variable="newAnchor" expression="$selectedNodes" />
             <!-- delete the original selected node(s) -->
               <set variable="selectedNodes" expression="$anchor" />
               <command name="delete" />
             <!-- reselect the moved element(s) -->
               <set variable="selectedNodes" expression="$newAnchor" />
           </sequence>
           <sequence> <!-- else, restore the original selection -->
             <set variable="selectedNodes" expression="$anchor" />
           </sequence>
         </choice>
       </sequence>
     </macro>
   </command>

   <binding>
     <keyPressed code="UP" modifiers="alt ctrl" />
     <command name="moveBefore" />
   </binding>


   <!-- 
=======================================================================
     Move the explicitly selected element(s) after the following element

======================================================================== -->

   <command name="moveAfter">
     <macro>
       <sequence>
         <!-- test for a following element, and record its location -->
           <choice>
             <sequence> <!-- multiple selection -->
               <match context="$selected2" pattern="*[position() &lt; 
last()]" />
               <set variable="newAnchor" context="$selected2"
                    expression="./following-sibling::*[1]" />
             </sequence>
             <sequence> <!-- single node selection -->
               <match context="$selected" pattern="*[position() &lt; 
last()]" />
               <set variable="newAnchor" context="$selected"
                    expression="./following-sibling::*[1]" />
             </sequence>
           </choice>
         <!-- copy the selected element(s) and record its location -->
           <command name="copy" parameter="[selectedNodes]" />
           <set variable="anchor" expression="$selectedNodes" />
         <choice>
           <sequence> <!-- there is an element after the following 
element -->
             <match context="$newAnchor" pattern="*[position() &lt; 
last()]" />
             <!-- record the location past the following element -->
               <set variable="newAnchor2" context="$newAnchor"
                    expression="./following-sibling::*[1]" />
             <!-- select now the following element -->
               <set variable="selected" expression="$newAnchor" />
             <choice>
               <sequence> <!-- try to complete the command -->
                   <command name="paste" parameter="after" />
                 <!-- select the whole set of pasted elements and record 
its location -->
                   <set variable="selected2" expression="$newAnchor2" />
                   <command name="selectNode" 
parameter="extendToPreviousSiblingOrNode" />
                   <set variable="newAnchor" expression="$selectedNodes" />
                 <!-- delete the original selected node(s) -->
                   <set variable="selectedNodes" expression="$anchor" />
                   <command name="delete" />
                 <!-- reselect the moved element(s) -->
                   <set variable="selectedNodes" expression="$newAnchor" />
               </sequence>
               <sequence> <!-- else, restore the original selection -->
                 <set variable="selectedNodes" expression="$anchor" />
               </sequence>
             </choice>
           </sequence>
           <sequence> <!-- there are no elements after the following 
element -->
             <!-- select now the following element -->
               <set variable="selected" expression="$newAnchor" />
             <choice>
               <sequence> <!-- try to complete the command -->
                   <command name="paste" parameter="after" />
                 <!-- select the whole set of pasted elements and record 
its location -->
                   <set variable="selected2" context="$newAnchor"
                        expression="./following-sibling::*[last()]" />
                   <set variable="newAnchor" expression="$selectedNodes" />
                 <!-- delete the original selected node(s) -->
                   <set variable="selectedNodes" expression="$anchor" />
                   <command name="delete" />
                 <!-- reselect the moved element(s) -->
                   <set variable="selectedNodes" expression="$newAnchor" />
               </sequence>
               <sequence> <!-- else, restore the original selection -->
                 <set variable="selectedNodes" expression="$anchor" />
               </sequence>
             </choice>
           </sequence>
         </choice>
       </sequence>
     </macro>
   </command>

   <binding>
     <keyPressed code="DOWN" modifiers="alt ctrl" />
     <command name="moveAfter" />
   </binding>

-------------------------------------

Regards.
-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

 
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support

Reply via email to