title: Xquery get next specific element
body: <p>I hava Problem with Xquery </p>
  
  <p>I have an XML document like this </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;bpmn2:definitions ....."&gt;
    &lt;bpmn2:process id="process_3" drools:version="1" drools:packageName="defaultPackage"drools:adHoc="false" name="Default Process" isExecutable="true"&gt;
      &lt;bpmn2:startEvent id="StartEvent_1" name=""&gt;
        &lt;bpmn2:outgoing&gt;SequenceFlow_3&lt;/bpmn2:outgoing&gt;
      &lt;/bpmn2:startEvent&gt;
      &lt;bpmn2:endEvent id="EndEvent_1" name=""&gt;
        &lt;bpmn2:incoming&gt;SequenceFlow_4&lt;/bpmn2:incoming&gt;
      &lt;/bpmn2:endEvent&gt;
      &lt;bpmn2:sequenceFlow id="SequenceFlow_3" name="Sequence Flow 3" sourceRef="StartEvent_1" targetRef="ManualTask_1"/&gt;
      &lt;bpmn2:manualTask id="ManualTask_1" timeToComplete="300" name="Manual Task 1"&gt;
        &lt;bpmn2:incoming&gt;SequenceFlow_3&lt;/bpmn2:incoming&gt;
        &lt;bpmn2:outgoing&gt;SequenceFlow_1&lt;/bpmn2:outgoing&gt;
      &lt;/bpmn2:manualTask&gt;
      &lt;bpmn2:manualTask id="ManualTask_2" timeToComplete="200" name="Manual Task 2"&gt;
          &lt;bpmn2:incoming&gt;SequenceFlow_1&lt;/bpmn2:incoming&gt;
          &lt;bpmn2:outgoing&gt;SequenceFlow_4&lt;/bpmn2:outgoing&gt;
      &lt;/bpmn2:manualTask&gt;
      &lt;bpmn2:sequenceFlow id="SequenceFlow_1" name="Sequence Flow 1" sourceRef="ManualTask_1" targetRef="ManualTask_2"/&gt;
         &lt;bpmn2:sequenceFlow id="SequenceFlow_4" name="Sequence Flow 4" sourceRef="ManualTask_2" targetRef="EndEvent_1"/&gt;
    &lt;/bpmn2:process&gt;
  &lt;/bpmn2:definitions&gt;
  </code></pre>
  
  <p>I want to get the next element.(the outgoing sequenceflow from the last element should be de incoming element(sequenceflow) (so an manualTask or an EndEvent (or as its simplified something different) (All those elements have the tag incoming ) </p>
  
  <pre><code>declare namespace bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL";
  
  let $elements := doc('file:///C:\..\process3.txt')/bpmn2:definitions/bpmn2:process,
  $e := $elements/bpmn2:startEvent
  return  $elements[//bpmn2:incoming/node() = $e//bpmn2:outgoing]
  </code></pre>
  
  <p>This returns in BaseX just the complete $elements and not  .. and at the moment I think much to difficult.. </p>