Below is an XSLT solution to my swapping problem. It was quite interesting that it took the XSLT engine I was using (MSXML4.0) over 21 seconds to generate an output file on my 3MB input (45K+ XML nodes). The Perl program I posted last week generated an output file in a couple of seconds.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/T +ransform"> <!-- 12/01/2005 jkulas@lsijax.com --> <!-- This transforms figure by moving title to last_child position + --> <!-- Functionally similar to twig_roots --> <xsl:template match ="figure"> <xsl:element name="figure"> <xsl:copy-of select="@*"/> <xsl:apply-templates/> <!-- Add the title node as last child--> <xsl:if test="title"> <xsl:element name ="title"> <xsl:copy-of select="title/@*"/> <xsl:copy-of select="title/text()"/> </xsl:element> </xsl:if> </xsl:element> </xsl:template> <!-- Ignore any figure/title's since they are handled in the figur +e template--> <xsl:template match ="figure/title"> </xsl:template> <!-- Copy all nodes, except figure nodes (of course)--> <!-- Adapted from Michael Kay, _XSLT 2.0_, 3/e, p. 243--> <!-- Functionally similar to twig_print_outside_roots --> <xsl:template match ="@* | node()"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Peace,
--Jack

In reply to Re^2: Swapping XML Elements by peace
in thread Swapping XML Elements by peace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.