如何獲取條件名爲「task1」,value =「abc」AND name =「task2」,value =「efg」name =「task5」,value =「nop」XPATH解析複雜數據的問題
預期輸出:ABC-123; XYZ-987
實際輸出:XYZ-987
查詢:/node1/node2/node3[condition/task[@name='task1' and @value='abc'] and condition/task[@name='task2' and @value='efg'] and condition/task[@name='task5' and @value='nop'] and count(condition/task)=3]/id
查詢從How to parse and fetch exact result from XML using XPATH
捕捉提到,如果在任務,比納的任務外,所有的操作都是 「OR」,那麼該ID也應該被認爲是滿意的條件。在下面的XML中,ABC-123,LMN-543和XYZ-987滿足條件,但ABC-123具有所有其他操作=「或」。所以這也應該包含在結果中。通過使用計數,我限制爲3個任務,因此不包括ABC-123。使用count> 3將獲取ABC-123,LMN-543和XYZ-9876。
需要輸出爲ABC-123; XYZ-987使用的操作條件檢查=或
以下 是所使用的XML
<node1>
<node2>
<node3>
<id>ABC-123</id>
<condition>
<task name="task1" operation="and" value="abc" />
<task name="task2" operation="and" value="efg" />
<task name="task3" operation="or" value="hij" />
<task name="task4" operation="or" value="klm" />
<task name="task5" operation="or" value="nop" />
<task name="task6" value="uvw" />
</condition>
</node3>
<node3>
<id>LMN-543</id>
<condition>
<task name="task1" operation="and" value="abc" />
<task name="task2" operation="and" value="efg" />
<task name="task3" operation="and" value="hij" />
<task name="task4" operation="or" value="klm" />
<task name="task5" operation="or" value="nop" />
<task name="task6" value="uvw" />
</condition>
</node3>
<node3>
<id>XYZ-987</id>
<condition>
<task name="task1" operation="and" value="abc" />
<task name="task2" operation="and" value="efg" />
<task name="task5" operation="or" value="nop" />
</condition>
</node3>
<node3>
<id>RST-567</id>
<condition>
<task name="task1" operation="and" value="abc" />
<task name="task2" operation="and" value="efg" />
<task name="task8" operation="and" value="jkl" />
<task name="task9" operation="and" value="rst" />
<task name="task10" value="xyz" />
</condition>
</node3>
<node3>
<id>PQR-345</id>
<condition>
<task name="task1" operation="and" value="ijk" />
<task name="task2" operation="and" value="klm" />
<task name="task8" operation="and" value="jkl" />
<task name="task9" operation="and" value="rst" />
</condition>
</node3>
</node2>
</node1>
請參閱任務數這個問題再次。你已經提供了我已經使用的。我需要擺脫LMN-543。任何解決方案? –
編輯答案添加運算符的附加約束 – Daniele