View Single Post
  #1 (permalink)  
Old March 15th, 2011, 09:07 AM
lkd lkd is offline
Registered User
 
Join Date: Mar 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to MOVE sub-element to preceding-sibling’s last sub-element

I need an XSL rule to move an XML sub-element to print before the preceding-sibling’s last sub-element (<tools> or it could be <parts>). My if statement is:

Quote:
IF (/work/prelim/tools OR /work/prelim/parts) AND /work/main/planning exist in the XML,
THEN
MOVE /work/main/planning to print BEFORE (/work/prelim/tools OR /work/prelim/parts)
OTHERWISE just <apply-templates />.
I've tried several things, but I just can't get it to print before <tools> (or in some files, it's <parts>).

XML is as follows:

Code:
    <work>
        <prelim>
            <code>ABC</code>
            <source>DEF</source>
            <tools>Includes codes for a table</tools>
        </prelim>
        <main>
            <planning>Text for Planning</planning>
            <p>blah blah blah</p>
        </main>
    </work>
I want my output to be as follows (if the above condition exists):

Code:
    <work>
        <prelim>
            <code>ABC</code>
            <source>DEF</source>
            <planning>Text for Planning</planning>
            <tools>Includes codes for a table</tools>
        </prelim>
        <main>
            <p>blah blah blah</p>
        </main>
    </work>
Can anyone help me on how to achieve this?

Thanks in advance!!

lkd
Reply With Quote