2015-05-24 59 views
1

我拼命嘗試在xpath中組合多個過濾器。假設我的數據看起來像這樣:xpath:在同一水平上組合多個過濾器

<Table name="MyTable1"> 
    <Item> 
    <Status date="2015-03-01" category="one/two">DELETE</Status> 
    <Old /> 
    <Current> 
     <Field name="ID">1</Field> 
     <Field name="Title">This is my title</Field> 
     <Field name="Short_title">my short title</Field> 
     <Field name="Order">1</Field> 
    </Current> 
    </Item> 
    <Item> 
    <Status date="2015-03-01" category="one/two">EQUAL</Status> 
    <Old /> 
    <Current> 
     <Field name="ID">2</Field> 
     <Field name="Title">here comes another title</Field> 
     <Field name="Short_title">another short one</Field> 
     <Field name="Order">2</Field> 
    </Current> 
    </Item> 
</Table> 

我的願望是訪問所有「當前」 -nodes是

  • 包含狀態類別「兩節」
  • 狀態,其不 包含「刪除」

我試圖將幾個被問的問題在計算器:

例如我的查詢之一將是:

  • /Table/Item[Status[[contains(@category,'two')] AND [not(contains('DELETE')]]/Current

任何想法可能是什麼一個bett呃方法?

回答

2

您可以使用以下XPath表達:

//Status[contains(@category,"two") and not(text()="DELETE")]/following-sibling::Current 
+0

非常感謝您的快速回答。你已經幫了很多! – Tomukas

+0

我很高興看到它幫助 – hek2mgl

1

您只需將兩個布爾表達式與and直接,不要把每一個身邊的表達方括號。 :

/Table/Item[Status[contains(@category,'two') and not(contains(., 'DELETE'))]]/Current 
+0

非常感謝您的快速回答。你已經幫了很多! – Tomukas