Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

How to loop over in Xquery and compare the values within loops

RAMMIIMay 24 2017 — edited Jun 11 2017

I am new to Xquery , i have something tricky requirement.

Below is the sample xml for my requirement and tabled the values below. There are four(can be more ) titlcodes in each class type within network, from this i would like to form a key for each title code combination of  two networks and put them under titlecode range and max repeatable key will be at  Range at class. Provide input and expected xml also below.

Any pointers how to achieve that would be helpful, if not through x query is there any other approach to do this?

Classtype =23/ title codes         

AA

AB

key

P1

100

100

100_100

P2

  80

50

80_50

P3

80

80

80_80

P4

80

50

80_50

Input :

<root>

<ns1:Network>

    <ns1:description>AA</ns1:description>

    <ns1:classType>

        <ns1:class>23</ns1:class>

        <ns1:RangeAtClass>100</ns1:RangeAtClass>

        <ns1:title>                  

            <ns1:titleCode>P1</ns1:titleCode>                  

            <ns1:titleRange>100</ns1:titleRange>      

        </ns1:title>

        <ns1:title>

            <ns1:titleCode>P2</ns1:titleCode>

            <ns1:titleRange>80</ns1:titleRange>

        </ns1:title>

        <ns1:title>

            <ns1:titleCode>P3</ns1:titleCode>

            <ns1:titleRange>80</ns1:titleRange>

        </ns1:title>

        <ns1:title>

            <ns1:titleCode>P4</ns1:titleCode>

            <ns1:titleRange>80</ns1:titleRange>

        </ns1:title>      

    </ns1:classType>

</ns1:Network>

<ns1:Network>

    <ns1:description>AB</ns1:description>

    <ns1:classType>

        <ns1:class>23</ns1:class>

        <ns1:RangeAtClass>100%</ns1:RangeAtClass>

        <ns1:title>                  

            <ns1:titleCode>P1</ns1:titleCode>                  

            <ns1:titleRange>100</ns1:titleRange>      

        </ns1:title>

        <ns1:title>

            <ns1:titleCode>P2</ns1:titleCode>

            <ns1:titleRange>50</ns1:titleRange>

        </ns1:title>

        <ns1:title>

            <ns1:titleCode>P3</ns1:titleCode>

            <ns1:titleRange>80</ns1:titleRange>

        </ns1:title>

        <ns1:title>

            <ns1:titleCode>P4</ns1:titleCode>

            <ns1:titleRange>50</ns1:titleRange>

        </ns1:title>      

     </ns1:classType>  

</ns1:Network>

</root>

Expected OUTPUT:

<root>

<ns1:Network>

                <ns1:description>AA</ns1:description>

                <ns1:classType>

                                <ns1:class>23</ns1:class>

                                <ns1:RangeAtClass>80</ns1:RangeAtClass>   (first value of max occurrence key)

                                <ns1:title>                                                            

                                                <ns1:titleCode>P1</ns1:titleCode>                                                                      

                                                <ns1:titleRange>100_100</ns1:titleRange>                       

                                </ns1:title>

                                <ns1:title>

                                                <ns1:titleCode>P2</ns1:titleCode>

                                                <ns1:titleRange>80_50</ns1:titleRange>

                                </ns1:title>

                                <ns1:title>

                                                <ns1:titleCode>P3</ns1:titleCode>

                                                <ns1:titleRange>80_80</ns1:titleRange>

                                </ns1:title>

                                <ns1:title>

                                                <ns1:titleCode>P4</ns1:titleCode>

                                                <ns1:titleRange>80_50</ns1:titleRange>

                                </ns1:title>                      

                </ns1:classType>

</ns1:Network>

<ns1:Network>

                <ns1:description>AA</ns1:description>

                <ns1:classType>

                                <ns1:class>23</ns1:class>

                                <ns1:RangeAtClass>50</ns1:RangeAtClass> (second value of max occurrence key)

                                <ns1:title>                                                            

                                                <ns1:titleCode>P1</ns1:titleCode>                                                                      

                                                <ns1:titleRange>100_100</ns1:titleRange>                       

                                </ns1:title>

                                <ns1:title>

                                                <ns1:titleCode>P2</ns1:titleCode>

                                                <ns1:titleRange>80_50</ns1:titleRange>

                                </ns1:title>

                                <ns1:title>

                                                <ns1:titleCode>P3</ns1:titleCode>

                                                <ns1:titleRange>80_80</ns1:titleRange>

                                </ns1:title>

                                <ns1:title>

                                                <ns1:titleCode>P4</ns1:titleCode>

                                                <ns1:titleRange>80_50</ns1:titleRange>

                                </ns1:title>                      

                 </ns1:classType>          

</ns1:Network>

</root>

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 9 2017
Added on May 24 2017
5 comments
13,168 views