Retrive n number of elements from the collection using XQUERY

<?xml version="1.0"?>
<ns0:PNR >
    <ns0:num>num_1</ns0:num>
    <ns0:num>num_2</ns0:num>
    <ns0:num>num_3</ns0:num>
    <ns0:num>num_4</ns0:num>
    <ns0:num>num_5</ns0:num>
    <ns0:num>num_6</ns0:num>
    <ns0:num>num_7 </ns0:num>
</ns0:PNR>
In the above XMl i need an xquery to get below response:
<ns1:PNRSet >
<ns1:set>
<ns0:num>num_1</ns0:num>
    <ns0:num>num_2</ns0:num>
</ns1:set>
<ns1:set>
<ns0:num>num_3</ns0:num>
    <ns0:num>num_4</ns0:num>
</ns1:set>
<ns1:set>
<ns0:num>num_5</ns0:num>
    <ns0:num>num_6</ns0:num>
</ns1:set>
<ns1:set>
<ns0:num>num_7</ns0:num>
</ns1:set>
</ns1:PNRSet>

Declare @x xml ='<?xml version="1.0"?>
<ns0:PNR xmlns:ns0="whatever">
<ns0:num>num_1</ns0:num>
<ns0:num>num_2</ns0:num>
<ns0:num>num_3</ns0:num>
<ns0:num>num_4</ns0:num>
<ns0:num>num_5</ns0:num>
<ns0:num>num_6</ns0:num>
<ns0:num>num_7 </ns0:num>
</ns0:PNR>';
with xmlnamespaces ('whatever' as ns0, 'the other' as ns1)
, num as (
select num from (values(0), (1),(2),(3), (4), (5), (6), (7),(8),(9),(10)) x(num)
), setFull as (
select num / 2 as setNum, num + 1 as num
from num n
), setNum as (
select distinct setNum
from setFull
where @x.exist('/ns0:PNR/ns0:num[position() = sql:column("num")]') = 1
select
(Select
x.val.query('.')
from setFull s
cross apply @x.nodes('/ns0:PNR/ns0:num[position() = sql:column("num")]') x(val)
where n.setNum = s.setNum
for xml path (''), type)
from setNum n
for xml path ('ns1:set'), root('ns1:PNRSet')
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Similar Messages

  • Delete element from a collection (JDev 10.1.2)

    Hello
    I have a bean which has a collection "testCollection" and accessors for it. This has been populated with some elements (similar to the LDAPDataControls example). I have created the data control for it and dragged the collection onto a JSP as a read only form. This displays the current element of the collection depending on the iterator position.
    I then have a forward on the page using a button to a Data Action called RemoveAction. I have overwritten invokeCustomMethod and I'm trying to remove the element in the collection at the current iteraotr position.
    I can access the iterator using actionContext.getBindingContainer().findIterator("testCollectionIterator");
    From this I can get the current row but both row.remove() and row.removeFromCollection throw UnsupportedMethod exceptions.
    I can access the collection using actionBinding.getBindingContainer().getDataControl().getDataProvider(), but I have no way of removing the object from the collection without having a reference to the object itself.
    Please can someone explain how to remove elements from the collection?
    Also can someone explain in the LDAPDataControls example why its also necessary to have a class called LDAPDataControl (type of DCGenericDataControl) and a LDAPDataControlFactory (type of DataControlFactoryImpl)?
    Just having the classes LDAPSearch, the bean class LDAPEntry, and a class to hold the collection LDAPCollection works fine. Create the data control for LDAPCollection and drag the collection onto the JSP.
    Thanks.

    I'm still not sure about this. Can anyone help? Thanks.

  • How to get page number from the PDF using Javascript

    Hi,
    We are having list of Single page PDF. The pdf are named in the order,
    ISBN_Author_01.PDF  (with real page number as i)
    ISBN_Author_02.PDF  (with real page number as ii)
    ISBN_Author_03.PDF  (with real page number as iii)
    ISBN_Author_04.PDF  (with real page number as 1)
    ISBN_Author_05.PDF  (with real page number as 2)
    ISBN_Author_06.PDF  (with real page number as 3)
    ISBN_Author_nn.PDF  (with real page number as 500)
    Here each pdf has a page number and in sequential order.
    The task is to check whether all the pdfs are in sequential order (i.e i, ii, iii, 1, 2, 3). If any page is missing, the script should throw an error report.
    To do this task, I am writing a Javascript to get the real page number from the PDF.
    Can anybody help me how to get the page number from the PDF using Javascript.
    Thanks,
    Gopal

    The "real" page number within a PDF is the count of the physical page starting at 0, zero.
    pageNum numPages
    The number printed on each page is the page label.
    setPageLabels  getPageLabel
    You will have to open each PDF and your script would need to know the page label for that file. I would expect you would need to build a 2 dimensional  array of the file names and the page label for the page within that array.

  • In list view: Why don't searches include results from the Collections field? Why won't the Collections column sort properly?

    In list view: Why don't searches include results from the Collections field? Why won't the Collections column sort properly?

    I create a new index on column2, (INDEX_N3)
    and change SQL to
    select 1 from table T1 where
    T1.COLUMN_002 = '848K 36892'
    This time INDEX_N3 will be used.
    but change SQL to
    select 1 from table T1 where
    T1.COLUMN_002 = '848K 36892'
    and T1.COLUMN_004 = '1000'
    The explain plan will show full scan.
    Why?
    Thanks.

  • Any Reports show PM Orders Number, GL Number, Cost Element and the amount?

    Hi Experts,
    Are there any reports that display the PM Orders Number, GL Number, Cost Element and the amount?
    currently i have to use IW32 and click the COSTS tab then click button REP.PLAN/ACT. to view these information.
    Please Advise
    Thank you
    Regards

    There is no single report to show all the data. You have to use different reports or develop custom report.

  • How to save only newly added elements from the trailing list

    Dear,
    I have a shuttle bean with left and right trailing lists.
    At some point I save the right trailing list content to DB. Then I add additinal elements to the trailing list. Trying to save again gives me oracle.jbo.TooManyObjectsException: JBO-25013: Too many objects match the primary key oracle.jbo.Key
    exception.
    What is the approach I can take to only save newly added elements from the shuttle?
    I am wondering if I can put the extra logic (what logic would that be - do I need to check the PK value that is already in the database?) in the AM method with which I save the shuttle like here (TicketID and ResponsibilityID are primary key)
    if (items != null)
    Object ia[] = items.toArray();
    for(int i=1; i<ia.length; i++)
    Row rowApproval = vo.createRow();
    vo.insertRow(rowApproval);
    rowApproval.setNewRowState(Row.STATUS_INITIALIZED);
    Row row = vo.getCurrentRow();
    row.setAttribute("TicketId",items.get(0));
    row.setAttribute("ResponsibilityId",items.get(i) );
    row.setAttribute("Status",items.get(i));
    or should I do something in the EO?
    Thank you
    Anatoliy

    Hi,
    Can you please clarify - do I have to make a loop? I mean for every record/element in the trailing list
    I run the VO (that I will create) VO.executeQuery?Yes you do need to execute the VO for every record....by passing the different parameter in each iteration.
    Regards,
    Gyan

  • I want to get rid of a book in the iBooks "Purchased" collection, but when I touch the Edit button and select the book and then touch the Delete button, then the "Delete this copy" seletion, nothing happens.  How do I delete the book from the collection?

    I want to get rid of a book in the iBooks "Purchased" collection, but when I touch the Edit button and select the book and then touch the Delete button, then the "Delete this copy" seletion, nothing happens.  How do I delete the book from the collection?

    The Cloud by the song indicates that is is an iTunes purchase but it is not downloaded on the iPod. If you only want download iTunes purchases to show in the Music app go to Settings>itunes and pp Store and turn off Show aLL.

  • How to get customer number and name from the SD document

    Hi All,
    Can you please let me know how to get Customer Number and Name from the SD Document?
    Thanks a lot....
    Anil

    Hi,
    It will be displayed in the SD (BIlling document) itself,  you clikc on the VF03. The customer name and number will also appear in the SO document also Tcode VA03
    regards,
    radhika
    Edited by: kolipara radhika on Jul 10, 2009 5:32 AM

  • Anyone bought Photoshop Elements from the Apps Store just recently?

    Anyone bought Photoshop Elements from the Apps Store, either recently (April 2014) or in the last 12 months, say? The version on the Apps Store is just the editor and so doesn't incorporate an organiser.
    I'm just wondering if anyone happens to know whether the Store edition of this app includes support for Canon RAW files of the CR2 type. I've looked all over the Adobe website for the answer but without success.

    Hi..
    You can post a question in the Adobe Photoshop Elements forum here.

  • Accessibility, exclude UI elements from the Tab-chain

    Hi,
    I have a complex UI which is very uncomfortable to access with the Tab key when using sap-accesssibility=true parameter. The main problem are the many transparent containers, which are necessary to create the refined composition of the UI. They get focused when the Tab key is pressed and this is completely useless. I there a way to exclude UI elements from the Tab-chain?
    Best regards,
    Krasimir

    Hi,
    I have same prolem here.
    In my UI I am using mastercolumn for expand /collapse functionality in parent - child node .
    The problem is the keyboard tab-chain is skipping the master column which makes it a accessibility issue.
    Is there any way we can include/exclude UI elements from tab chain.
    My NWDS version is 7.0.10.

  • Kill a thread and remove the element from the vector

    Hi All
    I have attached each Vector element to a thread which I later want to kill and remove that element from the Vector.
    Thread.join(milliseconds) allows this functionality to let the thread die after n milliseconds.
    However, I want to delete this element from the Vector now.
    Can someone please throw some light on this?
    Here the code I have written for this:
    try
         System.out.println(counter);
         int xCoord = generator.irand(25,200);     // X-coord of AP
         int yCoord = generator.irand(25,200);     // Y coord of AP
         listMN.addElement(new MobileNode((int)mnId,new Point2D.Double(xCoord,yCoord)));
         listMNcoords.addElement(new Point2D.Double(xCoord,yCoord));
         for(int i=0;i<vnuBS.returnBSList().size();i++)
              if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=3)&&(vnuBS.returnBSList().get(i).getChannelCounter()>0))
                   double c = exponential() * 10000;
                   long timeToService = (long)c;
                   System.out.println("BS "+vnuBS.returnBSList().get(i).id+" is connected to MN ");
                   vnuBS.returnBSList().get(i).reduceChannelCounter();
                   System.out.println("Channel Counter Value Now: "+vnuBS.returnBSList().get(i).getChannelCounter());
                   mobileNodesThread.addElement(new Thread(listMN.elementAt(mobileNodeCounter)));
                   mobileNodesThread.elementAt(mobileNodeCounter).setName(mobileNodeCounter+"");
                   mobileNodesThread.elementAt(mobileNodeCounter).start();
                   mobileNodesThread.elementAt(mobileNodeCounter).join(100);
    //                              System.out.println("Died");// thread dies after join(t) milliseconds.
                   System.out.println("ListMN getting generated : " + mobileNodesThread.get(mobileNodeCounter));
              else if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=0))
                   listMN.remove(this.listMN.lastElement());                         //dropcall
                   System.out.println("Removed "+mnId);
                   removeCounter++;
                   mnId = mnId--;
                   mobileNodeCounter--;
              mnId = mnId+1;
         Thanks a lot.

    I'm not sure if what you are trying to accomplish is correctly implemented.
    The method join does not kill the thread. It will wait for the specified time for the thread to exit. If you want the thread to run for a specified ammount of time, develop the run method of that thread with that in mind. Do not try to kill it from the outside, but let it terminate itself (gracefull termination).
    Now for your question regarding the vector (you should probably be using ArrayList nowadays): I would implement the observer pattern for this job. Make the threads post an event on the interface when they are done, let the main thread register itself with the threads and synchronize the method that handles the events. In that method you can remove the object from your list.
    I'm not sure if you want to use thread anyhow, could you tell us what it is that you are trying to accomplish?

  • Help with how to count the number of tokens from the first line

    Hi
    I want to count the number of tokens from the first line of text, from my incoming file and print it out.
    For example i have 12 tokens in the first line, so i want it to print out the number 12
    my code is below
    thanks
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.util.StringTokenizer.*;
    import java.sql.*;
    public class Data {
         public static void main(String[] args) {
                        String token = null;          
                        String currentToken = "";
                        Hashtable hh = new Hashtable();     
              try {
                   Vector v2 = new Vector(100);
                   Vector v = new Vector(100);
                   FileReader file = new FileReader("words.txt");
                   BufferedReader buff = new BufferedReader(file);
                   String line = buff.readLine();
                   StringTokenizer s = null;
                   boolean eof = false;
                   while  (!eof){
                        s = new StringTokenizer(line.trim(),",",true);
                        boolean lastToken = true;
                   while (s.hasMoreTokens()) {
                              token = s.nextToken();
                                  if (lastToken){
                                   if (token.equals(",")) {
                                        v.add("");
                                               lastToken = false;
                                      if (! token.equals(",")) {
                                   v.add(token);
                                  else { if (currentToken.equals(",")) {
                                        v.add("");
                                  currentToken = token;
                        if (token.equals(",")) {
                               v.add("");
                   line = buff.readLine();
                        if (line == null){     
                             eof = true;}
                   buff.close();
              }catch (FileNotFoundException fe) {     
                        System.out.println("Error - - " + fe.toString());
              }catch (NumberFormatException ne) {
                        System.out.println("Error - - " + ne.toString());
              } catch (IOException e) {
                   System.out.println("Error - - " + e.toString());
    }     2.

    I can print out the amount of tokens from each line,
    But i only want the first line to be counted, And i
    also do not want the delimeters to be counted.
    could you please give me some ideas?
    Thanks
    try
       BufferedReader br = new BufferedReader(new FileReader("item.kr"));
       while((str=br.readLine())!= null)
          itemslist.add(str);
    catch(IOException ioe)
       System.out.println("Exception Occurred!!!");
    }This snippet gets one Line from the item.kr file.
    Then i would count (By useing a diffrent String Tokenizer) to count only this line!!!

  • Remove RDSH from the collection

    Hi,
    Deployment:RDS 2012 R2 provides RemoteApp...
    HA is not configured but round robin is created for the FARM_name of 2 brokers
    Currently only one RDSH provides Remote App.
    Yesterday, I added CALs to Licensing server. AND added second RDSH into collection for providing CALs from License server.
    This morning I got a trouble call... Clients could not connect to Remote App.
    1. first thing I checked licensing server. I found issued Licenses.
    2. then I connected to RDSH1 (that currently has all roles) by RDP and received the Message (didn't save a message)t: but it was like this: connections are redirected to RDSH2 ... for connection use the FARM NAME.
    To remind : HA was not touched yet.
    As a QUICK solution I shut down RDSH2 and everything works. Couldn't think that adding second RDSH to collection will create this kind of problem...
    My question:
    would you recommend to remove RDSH2 from the collection until starting HA configuration ?
    Could it create some problems when I will need to add it to collection?
    Thx.
    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Hi Miles,
    As per my research, if simply you would add the RDSH server then it would face this issue as redirection of server take place and it would find for user\App on other server. So now after adding RDSH server, you need to point the RD License server to RDSH server
    (Specify a License Server for an RD Session Host Server to Use) so that it can identify the License and user and can provide access to the server by your users.
    You can do this thing by following below group policy setting.
    Computer Configuration\Policies\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Licensing
    Use the specified Remote Desktop license servers:
    Enable it and add the FQDN name of server. 
    You can also configure through deployment properties and below powershell command.
    To configure the license server on RDSH/RDVH:
    $obj = gwmi -namespace "Root/CIMV2/TerminalServices" Win32_TerminalServiceSetting
    $obj.SetSpecifiedLicenseServerList("License.contoso.com")
    More information.
    RD Licensing Configuration on Windows Server 2012
    http://blogs.technet.com/b/askperf/archive/2013/09/20/rd-licensing-configuration-on-windows-server-2012.aspx
    Please check below article for reference.
    http://technet.microsoft.com/en-in/library/cc770585.aspx
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • I am trying to install photoshop elements from the shop bought card. After I put in redemption code the yellow line came up with "redemption is not available at the moment". What do I do?  Please help! Many thanks

    I am trying to install photoshop elements from the shop bought card. After I put in redemption code the yellow line came up with "redemption is not available at the moment". What do I do?  Please help! Many thanks

    There's been a few of these today. I think there must be a problem with the redemption server and you probably just need to wait a while and try again.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • I need my application to be able to open a .pdf file which was previously synced to the iBooks PFDs Collection. I then wish to remove the file from the collection and send it to email.

    I need my application to be able to open a .pdf file which was previously synced to the iBooks PFDs Collection. I then wish to remove the file from the collection and send it to email.

    I opened one of the PDF files in notepad and these are the first couple lines:
    瀖ᕁމጿ␠씴豈䧉筩롈ꓳ劏ꎯ僪뚢頟뻏즏谀㿃夑퀉꟠鲲쮂⫉笿褡밤籞冁탁ӓ轸뿐笼ⵆ횰䄌ඁ淥ة寨闤⬅鳦팥링빨嬄敎უ婏㣴ً鮓ࣿꢚ㑀녲莒඼ိȆ䕇纍쉉籶뺝갞伐쮠᥏﯒넉釖ȓ겴☧ ἣ秵駻�䣞띰㖔流羀籔朼敨ꢉ糶당⬤俉膇䄐惡�ಹꛖ鍡恡ⱶᶜ�堷﹑ﱌ僿걄뎔æ䋷귪⛢⫐䅪䉙὿烶ꖆ႟ᗔ瘞狻틫儩六잶覱낵듘盋崾�ᦜ㺆௹뻹燴ឋ騙쬄ꏿ뽒煹�钼뇲腎稦ꃲ㈃沒ꔈ뺐뛽첑䘶畱䍣紻 ⁜哠鳾

Maybe you are looking for

  • Error while posting stock

    Hi, I am trying to do stock posting in MB1c and getting the error as below: "field selection for movement type 501/ acct 893025 differs for business area 033" Please suggest. Regards, Naveen

  • Having issues re-installing windows 7

    Ok I didn't make a recovery cd for my laptop I have tried to intall windows 7 again and looks like it went over the 1st one that was having problems so it still have issues booting up. How can i remove the old windows?

  • Mobile App problem after update from Flex SDK 4.5 to 4.5.1

    I have a mobile app that built in SDK 4.5 and running ok until update the SDK to 4.5.1 and then the app only loads the splash page and not even to to the firstview. The screen just stop at the splash page and no reaction, no debug window popup (test

  • VM, LINUX RAC on Win XP

    Hello all I'm truly a noob. I have a 32 bit XP OS that I plan to install 2 VMs - each running Enterprise Linux 5 Release 5. It will most likely have bad performance; but that's all I can afford right now as a student. The plan is to have 2 VMs and ho

  • Reg.Raise PO without PR against sales order number

    Dear priyanga I want to raise PO against sale order,How to configure against sale order (200000346). I configured against cost center for that I create Cost centre and G/L account and assignment that's all. Like what are the settings needed. Pls help