A correction in code due to small typo.


New Copy of Code:



xquery version "1.0-ml";



declare function local:is-node-in-sequence

  ( $node as node()*,

    $seq as xs:integer) as xs:boolean

{

  some $nodeInSeq in $node[1 to ($seq - 1)] satisfies $nodeInSeq eq $node[$seq]

} ;



declare function local:distinct-nodes ($nodes as node()* ) as node()*

{

  for $seq in (1 to count($nodes))

  return

  (

    $nodes[$seq][fn:not(local:is-node-in-sequence($nodes,$seq))]

  )

};



<Collections>

{

for $Collection in (

<Collections>

    <Collection No="0004157">

        <Document Date="2014-09-24" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0004157" Name="xcfty" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="ekff" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="fusifufj" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="CAdww" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2014-09-24" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0014157" Name="abaheue" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2014-09-24" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0024157" Name="ytrgebsd" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2015-02-25" Type="XYZ">

            <Counterparties>

                <Counterparty ClonedCollection="0004157" Name="rtryy" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="gdgdgdg" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="rryrhjtj" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="dgdgdgdg" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2015-02-25" Type="XYZ">

            <Counterparties>

                <Counterparty ClonedCollection="0014157" Name="gggdgd" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2015-02-25" Type="XYZ">

            <Counterparties>

                <Counterparty ClonedCollection="0024157" Name="bcbbccbb" 
Status="Active"/>

            </Counterparties>

        </Document>

    </Collection>

    <Collection No="0004302">

        <Document Date="2014-11-10" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0004302" Name="Invesco Active 
Multi-Sector Credit Fund, a sub-fund of Invesco Funds" Status="Active"/>

                <Counterparty ClonedCollection="0004302" Name="Invesco Asia 
Balanced Fund, a sub-fund of Invesco Funds" Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2014-11-10" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0014302" Name="Invesco Active 
Multi-Sector Credit Fund, a sub-fund of Invesco Funds" Status="Active"/>

            </Counterparties>

        </Document>

    </Collection>

    </Collections>

                   )/Collection

return

(

  <Collection>

  { $Collection/@No,

    for $Dstnct_Attr in local:distinct-nodes(

                                     for $Doc in $Collection/Document

                                     order by $Doc/@Date, $Doc/@Type

                                     return

                                     (

                                       <attr>

                                         <dt>

                                           {$Doc/@Date/string()}

                                         </dt>

                                         <tp>

                                           {$Doc/@Type/string()}

                                         </tp>

                                       </attr>

                                     )

                                   )

    return

    (

      <Document Date="{$Dstnct_Attr/dt/text()}" Type="{$Dstnct_Attr/tp/text()}">

      {

       (

        <Counterparties>

        {$Collection/Document[./@Date/string() eq 
$Dstnct_Attr/dt/text()][./@Type/string() eq 
$Dstnct_Attr/tp/text()]/Counterparties/Counterparty}

        </Counterparties>

       )

      }

      </Document>

    )

  }

  </Collection>



)

}

</Collections>





Thanks,



Ashish S Vaidya,

DB ADMINISTRATOR TECH SPEC

DGR (630) 737-5034  [email protected]





Data Classification : For Internal Use Only





-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Vaidya, Ashish
Sent: Thursday, February 25, 2016 11:34 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Xquery



Here is the Code.



xquery version "1.0-ml";



declare function local:is-node-in-sequence

  ( $node as node()*,

    $seq as xs:integer) as xs:boolean

{

  some $nodeInSeq in $node[$seq - 1] satisfies $nodeInSeq eq $node[$seq] } ;



declare function local:distinct-nodes ($nodes as node()* ) as node()* {

  for $seq in (1 to count($nodes))

  return

  (

    $nodes[$seq][fn:not(local:is-node-in-sequence($nodes,$seq))]

  )

};



<Collections>

{

for $Collection in (

<Collections>

    <Collection No="0004157">

        <Document Date="2014-09-24" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0004157" Name="xcfty" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="ekff" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="fusifufj" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="CAdww" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2014-09-24" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0014157" Name="abaheue" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2014-09-24" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0024157" Name="ytrgebsd" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2015-02-25" Type="XYZ">

            <Counterparties>

                <Counterparty ClonedCollection="0004157" Name="rtryy" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="gdgdgdg" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="rryrhjtj" 
Status="Active"/>

                <Counterparty ClonedCollection="0004157" Name="dgdgdgdg" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2015-02-25" Type="XYZ">

            <Counterparties>

                <Counterparty ClonedCollection="0014157" Name="gggdgd" 
Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2015-02-25" Type="XYZ">

            <Counterparties>

                <Counterparty ClonedCollection="0024157" Name="bcbbccbb" 
Status="Active"/>

            </Counterparties>

        </Document>

    </Collection>

    <Collection No="0004302">

        <Document Date="2014-11-10" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0004302" Name="Invesco Active 
Multi-Sector Credit Fund, a sub-fund of Invesco Funds" Status="Active"/>

                <Counterparty ClonedCollection="0004302" Name="Invesco Asia 
Balanced Fund, a sub-fund of Invesco Funds" Status="Active"/>

            </Counterparties>

        </Document>

        <Document Date="2014-11-10" Type="ABC">

            <Counterparties>

                <Counterparty ClonedCollection="0014302" Name="Invesco Active 
Multi-Sector Credit Fund, a sub-fund of Invesco Funds" Status="Active"/>

            </Counterparties>

        </Document>

    </Collection>

    </Collections>

                   )/Collection

return

(

  <Collection>

  { $Collection/@No,

    for $Dstnct_Attr in local:distinct-nodes(

                                     for $Doc in $Collection/Document

                                     order by $Doc/@Date, $Doc/@Type

                                     return

                                     (

                                       <attr>

                                         <dt>

                                           {$Doc/@Date/string()}

                                         </dt>

                                         <tp>

                                           {$Doc/@Type/string()}

                                         </tp>

                                       </attr>

                                     )

                                   )

    return

    (

      <Document Date="{$Dstnct_Attr/dt/text()}" Type="{$Dstnct_Attr/tp/text()}">

      {

       (

        <Counterparties>

        {$Collection/Document[./@Date/string() eq 
$Dstnct_Attr/dt/text()][./@Type/string() eq 
$Dstnct_Attr/tp/text()]/Counterparties/Counterparty}

        </Counterparties>

       )

      }

      </Document>

    )

  }

  </Collection>



)

}

</Collections>





And here is the Output:





<Collections>

<Collection No="0004157">

<Document Date="2014-09-24" Type="ABC">

<Counterparties>

<Counterparty ClonedCollection="0004157" Name="xcfty" Status="Active"> 
</Counterparty> <Counterparty ClonedCollection="0004157" Name="ekff" 
Status="Active"> </Counterparty> <Counterparty ClonedCollection="0004157" 
Name="fusifufj" Status="Active"> </Counterparty> <Counterparty 
ClonedCollection="0004157" Name="CAdww" Status="Active"> </Counterparty> 
<Counterparty ClonedCollection="0014157" Name="abaheue" Status="Active"> 
</Counterparty> <Counterparty ClonedCollection="0024157" Name="ytrgebsd" 
Status="Active"> </Counterparty> </Counterparties> </Document> <Document 
Date="2015-02-25" Type="XYZ"> <Counterparties> <Counterparty 
ClonedCollection="0004157" Name="rtryy" Status="Active"> </Counterparty> 
<Counterparty ClonedCollection="0004157" Name="gdgdgdg" Status="Active"> 
</Counterparty> <Counterparty ClonedCollection="0004157" Name="rryrhjtj" 
Status="Active"> </Counterparty> <Counterparty ClonedCollection="0004157" 
Name="dgdgdgdg" Status="Active"> </Counterparty> <Counterparty 
ClonedCollection="0014157" Name="gggdgd" Status="Active"> </Counterparty> 
<Counterparty ClonedCollection="0024157" Name="bcbbccbb" Status="Active"> 
</Counterparty> </Counterparties> </Document> </Collection> <Collection 
No="0004302"> <Document Date="2014-11-10" Type="ABC"> <Counterparties> 
<Counterparty ClonedCollection="0004302" Name="Invesco Active Multi-Sector 
Credit Fund, a sub-fund of Invesco Funds" Status="Active"> </Counterparty> 
<Counterparty ClonedCollection="0004302" Name="Invesco Asia Balanced Fund, a 
sub-fund of Invesco Funds" Status="Active"> </Counterparty> <Counterparty 
ClonedCollection="0014302" Name="Invesco Active Multi-Sector Credit Fund, a 
sub-fund of Invesco Funds" Status="Active"> </Counterparty> </Counterparties> 
</Document> </Collection> </Collections>







Thanks,



Ashish S Vaidya,





Data Classification : For Internal Use Only



-----Original Message-----

From: 
[email protected]<mailto:[email protected]>
 [mailto:[email protected]] On Behalf Of Florent Georges

Sent: Thursday, February 25, 2016 5:03 AM

To: MarkLogic Developer Discussion

Subject: Re: [MarkLogic Dev General] Xquery



On 25 February 2016 at 11:34, Kapoor, Pragya wrote:



> To be honest , I am still trying to get this output, but unable to get it.

> So, needed help.



It's always a good idea to help people to help you.  A few points to get better 
answers quicker:



- give a small example, showing clearly and only the problem

- explain your requirements (how to get from input to output)

- show what you tried, and corresponding output or error

- explain why the output you get is wrong, and what you cannot achieve



Usually, if you can get a small, clear, self-contained, reproducible example, 
people will spot the problem straight away and you will get an answer quickly.



Size does matter!  The smaller the example, the better :-)



In your case, the example input and output are not enough to guess what you are 
trying to achieve and why you cannot achieve it.



PS: Just found this, which might explain better what I am trying to

say: 
https://urldefense.proofpoint.com/v2/url?u=http-3A__stackoverflow.com_help_mcve&d=BQICAg&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=T9iTCnfsVIch-YNC2m4qxrhgtcjJ-j63_M6HVuAi-oY&m=5cJTxwzMpvIUvJc8EWDxNsrNx6vV2s9Um90AfE_r5cc&s=hoCUT5pzZ5IAiL2vkJw2VapwLLRd17HRUJ9sE7xoo7U&e=



Regards,



--

Florent Georges

https://urldefense.proofpoint.com/v2/url?u=http-3A__fgeorges.org_&d=BQICAg&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=T9iTCnfsVIch-YNC2m4qxrhgtcjJ-j63_M6HVuAi-oY&m=5cJTxwzMpvIUvJc8EWDxNsrNx6vV2s9Um90AfE_r5cc&s=BprsxM_flEJtGaoXHbP9iXY9GDAscAomE0T1g1S57Io&e=

https://urldefense.proofpoint.com/v2/url?u=http-3A__h2oconsulting.be_&d=BQICAg&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=T9iTCnfsVIch-YNC2m4qxrhgtcjJ-j63_M6HVuAi-oY&m=5cJTxwzMpvIUvJc8EWDxNsrNx6vV2s9Um90AfE_r5cc&s=TDcHNJQ9N9Ky-nhOq3zE7_HAgXAy1cRnk8-qZgX6t50&e=

_______________________________________________

General mailing list

[email protected]<mailto:[email protected]>

Manage your subscription at:

https://urldefense.proofpoint.com/v2/url?u=http-3A__developer.marklogic.com_mailman_listinfo_general&d=BQICAg&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=T9iTCnfsVIch-YNC2m4qxrhgtcjJ-j63_M6HVuAi-oY&m=5cJTxwzMpvIUvJc8EWDxNsrNx6vV2s9Um90AfE_r5cc&s=OYuVUo5ENwk9HRjIDlh-1hTs8ZgziZLKgITyMjDd9kE&e=



This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately. Thank you. Aetna 
_______________________________________________

General mailing list

[email protected]<mailto:[email protected]>

Manage your subscription at:

https://urldefense.proofpoint.com/v2/url?u=http-3A__developer.marklogic.com_mailman_listinfo_general&d=BQIFAw&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=T9iTCnfsVIch-YNC2m4qxrhgtcjJ-j63_M6HVuAi-oY&m=9MoA-i4BiDU-ido8SVsYYSy7GN-4loxCJfipPBA9FrE&s=XSq384cjOxl3o_kN6tcIIGN1-8dg4vH_tfhUUuqB0oM&e=

This e-mail may contain confidential or privileged information. If you think 
you have received this e-mail in error, please advise the sender by reply 
e-mail and then delete this e-mail immediately. Thank you. Aetna
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to