4 Replies Latest reply: Nov 29, 2012 6:48 AM by Adrian88 RSS

    xquery select and comparision in osb

    Adrian88
      Hi,

      I have xquery with two sources and one target, in each source there are the same for example 3 elements. This whole 6 elements are in target. I want to select and compare this elements and if 3 elements from first source is the same like in the second source I need to add an attribute to the response.

      For example my schema:

      source

      <element name="Response1" type="tns:Rep1"></element>
      <complexType name="Rep1">
           <sequence>
                <element name="Number" type="string"></element>
                <element name="Name" type="string"></element>
                <element name="ID" type="string"></element>
           </sequence>
      </complexType>

      <element name="Response2" type="tns:Rep2"></element>
      <complexType name="Rep2">
           <sequence>
                <element name="Number" type="string"></element>
                <element name="Name" type="string"></element>
                <element name="ID" type="string"></element>
           </sequence>
      </complexType>

      And target:

      <element name="RESPONSE" type="tns:REPP"></element>
      <complexType name="REPP">
           <sequence>
                <element name="Number" type="string"></element>
                <element name="Name" type="string"></element>
                <element name="ID" type="string"></element>
                <element name="Number" type="string"></element>
                <element name="Name" type="string"></element>
                <element name="ID" type="string"></element>
           </sequence>
      </complexType>
      </schema>


      Any idea?
        • 1. Re: xquery select and comparision in osb
          odie_63
          What attribute do you want to add? I don't see it in the target schema.

          Something like this?
          declare namespace tns = "http://xmlns.example.org";
          
          declare variable $src1 := <Response1 xmlns="http://xmlns.example.org"><Number>1</Number><Name>TEST</Name><ID>A</ID></Response1>;
          declare variable $src2 := <Response2 xmlns="http://xmlns.example.org"><Number>1</Number><Name>TEST</Name><ID>A</ID></Response2>;
          
          let $items1 := $src1/child::*
          let $items2 := $src2/child::*
          
          return element {QName("http://xmlns.example.org","RESPONSE")}
                 {
                   if (deep-equal($items1, $items2)) then
                     attribute isEqual {"true"}
                   else ()
                 , $items1
                 , $items2
                 }
          Edited by: odie_63 on 28 nov. 2012 20:54
          • 2. Re: xquery select and comparision in osb
            Adrian88
            I will explain in different way. I have two services which i will invoke parallel using split-join method. In each response from this two services there is a part that can have the same element with the same or different value. Next I will make "big" RESPONSE consisting from this two "small" response and I want to check if this two elements are equal. If all of these three elements are equal or not equal I want to mark it for example adding some attribute (own, foreign) to each part of RESPONSE. I want to get something like this:

            <RESPONSE>
                 <rep1>
            <x>OWN</x>
                 <Number>1</Number>
                 <Name>Test</Name>
                 <ID>123</ID>
            </rep1>
                 <rep2>
            <x>OWN</x>
                 <Number>1</Number>
                 <Name>Test</Name>
                 <ID>123</ID>
            </rep2>
            </RESPONSE>

            <RESPONSE>
                 <rep1>
            <x>OWN</x>
                 <Number>1</Number>
                 <Name>Test</Name>
                 <ID>123</ID>
            </rep1>
                 <rep2>
            <x>FOREIGN</x>
                 <Number>1</Number>
                 <Name>Test</Name>
                 <ID>123</ID>
            </rep2>
            </RESPONSE>

            It is possible to make something like this? :)

            Edited by: 935634 on 2012-11-29 01:01

            Edited by: 935634 on 2012-11-29 01:03
            • 3. Re: xquery select and comparision in osb
              odie_63
              You can try to explain in a different way, but it's not that much clear, especially if you keep changing the expected output.

              Which case should be tagged "OWN" or "FOREIGN"? Both last examples have the same data...

              If I understand correctly, it's not that much different from what I already suggested :
              declare variable $src1 := <Response1><Number>1</Number><Name>TEST</Name><ID>A</ID></Response1>;
              declare variable $src2 := <Response2><Number>1</Number><Name>TEST</Name><ID>B</ID></Response2>;
                
              element RESPONSE {
                element rep1 {
                  element x {"OWN"}
                , $src1/child::*
                }
              , element rep2 {
                  element x { 
                    if (deep-equal($src1/child::*, $src2/child::*)) then "OWN" else "FOREIGN"
                  }
                , $src2/child::*
                }
              }
              which will give :
              <RESPONSE>
                <rep1>
                  <x>OWN</x>
                  <Number>1</Number>
                  <Name>TEST</Name>
                  <ID>A</ID>
                </rep1>
                <rep2>
                  <x>FOREIGN</x>
                  <Number>1</Number>
                  <Name>TEST</Name>
                  <ID>B</ID>
                </rep2>
              </RESPONSE>
              • 4. Re: xquery select and comparision in osb
                Adrian88
                Yes, my mistake, the data should be different. Thanks a lot for help!