1 Reply Latest reply on May 17, 2013 1:43 AM by abhay kumar

    OSB: distinct values fucntion not working

    KalpanaJgl
      Hi,

      I have a below Xquery:

      <ns2:SR>
      {
      let $result :=
      for $cl in $clr/ns1:return/ns0:cld/ns3:cl,
      $xd in $cl/ns3:xd
      where $xd[fn:contains(ns3:ss,'abc')]
      return
      <ns2:SC>
      <ns2:aaa>abc_id</ns2:aaa>
      <ns2:bbb>EQUALS</ns2:bbb>
      <ns2:ccc>{ data($xd/ns3:si) }</ns2:ccc>
      </ns2:SC>
      return
      $result
      }

      Currently the above Xquery is returning:

      <mod:SM>
           <mod:entry>
           <mod:SR>
           <mod:SC>
           <mod:aaa>abc_id</mod:aaa>
           <mod:bbb>EQUALS</mod:bbb>
           <mod:ccc>577777</mod:ccc>
           </mod:SC>
           <mod:SC>
           <mod:aaa>abc_id</mod:aaa>
           <mod:bbb>EQUALS</mod:bbb>
           <mod:ccc>577777</mod:ccc>
           </mod:SC>
           <mod:operatorType>OR</mod:operatorType>
           </mod:SR>
           <mod:Operator>NO_OP</mod:Operator>
           </mod:entry>
           </mod:SM>

      The same <SC> i.e., duplicates are coming twice, how can i get the distinct values from here?

      Kindly advise.

      Edited by: KalpanaJgl on May 15, 2013 12:03 AM
        • 1. Re: OSB: distinct values fucntion not working
          abhay kumar
          You can modify the the following xquery to suit your requirement. The below xquey is returning distinct SC


          xquery version "1.0" encoding "Cp1252";
          (:: pragma parameter="$anyType1" type="xs:anyType" ::)
          (:: pragma type="xs:anyType" ::)

          declare namespace xf = "http://tempuri.org/Resources/Transformations/Test/";
          declare namespace mod = "http://tempuri.org/Resources/Transformations/";
          declare namespace functx = "http://www.functx.com";
          declare function functx:distinct-deep
          ( $nodes as node()* ) as node()* {

          for $seq in (1 to count($nodes))
          return $nodes[$seq][not(functx:is-node-in-sequence-deep-equal(
          .,$nodes[position() < $seq]))]
          } ;

          declare function functx:is-node-in-sequence-deep-equal
          ( $node as node()? ,
          $seq as node()* ) as xs:boolean {

          some $nodeInSeq in $seq satisfies deep-equal($nodeInSeq,$node)
          } ;

          declare function xf:Test($anyType1 as element(*))
          as element(*) {
          let $test :=<mod:SM>
          <mod:entry>
          <mod:SR>
          <mod:SC>
          <mod:aaa>abc_id</mod:aaa>
          <mod:bbb>EQUALS</mod:bbb>
          <mod:ccc>577777</mod:ccc>
          </mod:SC>
          <mod:SC>
          <mod:aaa>abc_id</mod:aaa>
          <mod:bbb>EQUALS</mod:bbb>
          <mod:ccc>577777</mod:ccc>
          </mod:SC>
          <mod:operatorType>OR</mod:operatorType>
          </mod:SR>
          <mod:Operator>NO_OP</mod:Operator>
          </mod:entry>
          </mod:SM>

          let $out :=<test>{functx:distinct-deep($test//*:SC)}</test>
               
               return $out
          };

          declare variable $anyType1 as element(*) external;

          xf:Test($anyType1)