[xquery-talk] moving an element from last child to next sibling

Martin Mueller martin.mueller at mac.com
Tue Oct 23 06:36:41 PDT 2012


I have used the xquery typeswitch function to transform elements from a TEI
file, but I am stymied by a task involving the following fragment:

    <closer>
               <signed>Your ever affectionate WOODVILLE.</signed>
               <postscript>
                  <p>P.S. You have a house, within a mile of York; where we
have spent many happy days—<q rend="inline">"Days of ease, and nights of
pleasure."</q> Who knows but we may there recover our juve‑nile tastes and
passions! impossible! As well when advanced in life, might we hope to
reco‑ver our youth, <hi>in those fields where we once were young.</hi>—But
is that house untenanted? Will you be our host? Or have you lett, or lent
it?</p>
               </postscript>
            </closer>

I want to move the <postscript> element from its position as the last child
of <closer> into the position of right sibling of <closer> so that the
desire output would look like this:

 <closer>
           <signed>Your ever affectionate WOODVILLE.</signed>
               
 </closer>
<postscript>
                  <p>P.S. You have a house, within a mile of York; where we
have spent many happy days—<q rend="inline">"Days of ease, and nights of
pleasure."</q> Who knows but we may there recover our juve‑nile tastes and
passions! impossible! As well when advanced in life, might we hope to
reco‑ver our youth, <hi>in those fields where we once were young.</hi>—But
is that house untenanted? Will you be our host? Or have you lett, or lent
it?</p>
</postscript>


How do I do this? In a typeswitch function the different tasks relating to
elements are carried out by subsidiary function. Here is the postscript
function that simply passes through the element:

declare function eccoparse:postscript($node as element(tei:postscript)) as
element() 
{
<postscript>{$node/@*}{eccoparse:recurse($node)}</postscript>
};



I know how to various things that would change the postscript element but
leave it in its current place. But how do I put it in another place without
changing anything in it?  Is this a task that should be done at the level of
the parent element?



I'll be grateful for any advice.





Martin Mueller

Professor emeritus of English and Classics

Northwestern University




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20121023/aeef61ca/attachment.html>


More information about the talk mailing list