[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to merge XML node including all the corresponding

Subject: How to merge XML node including all the corresponding children with unique element and latest value?
From: Lucent Lau <lucent.lau@xxxxxxxxx>
Date: Mon, 16 Jul 2012 23:54:10 +0700
 How to merge XML node including all the corresponding
I have this XSL:
<root>
    <library id="L1">
        <floor1 id="1">
            <shelf id="1">
                <book id="1" action="borrow">
                    <attributes>
                        <user>John</user>
                    </attributes>
                    <other1>y</other1>
                </book>
                <book id="1" action="extend">
                    <attributes>
                        <user>Woo</user>
                        <length>3</length>
                    </attributes>
                    <other2>y</other2>
                </book>
                <book id="2" action="extend">
                    <attributes>
                        <length>2</length>
                        <condition>ok</condition>
                    </attributes>
                    <other3>y</other3>
                </book>
            </shelf>
            <shelf id="2">
        </floor1>
        <floor1 id="2">..</floor1>
    </library>
</root>

Output:
<root>
    <library id="L1">
        <floor1 id="1">
            <shelf id="1">
                <book id="1" action="borrow">
                    <attributes>
                        <user>Woo</user>
                        <length>3</length>
                    </attributes>
                    <other1>y</other1>
                    <other2>y</other2>
                </book>

                <book id="2" action="extend">
                    <attributes>
                        <length>2</length>
                        <condition>ok</condition>
                    </attributes>
                    <other3>y</other3>
                </book>
            </shelf>
            <shelf id="2">
        </floor1>
        <floor1 id="2">..</floor1>
    </library>
</root>

I need to combine the node such that For every node that has the same
id with action=borrow followed by one or more node with action=extend

    Merge it together to the node with action=borrow.
    Merge the attributes children together such that it will have all
the unique attributes from the siblings with the latest value.
    leave other children unchanged

Please let me know how to fix this transformation using XSLT 2.0 ?

Thanks very much.
LL

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.