1

I'm desperately trying to combining several filters in xpath. Assume my data looks like that:

 <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>

My wish is to access all "Current"-nodes that

  • contain Status category "two"
  • have a Status which does not contain "DELETE"

I tried to combine several questions asked on stackoverflow:

For instance one of my queries would have been:

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

Any ideas what could be a better approach?

Tomukas
  • 13
  • 5

2 Answers2

2

You can use the following XPath expression:

//Status[contains(@category,"two") and not(text()="DELETE")]/following-sibling::Current
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
1

You can just combine two boolean expressions with and directly, don't put square brackets around each expression. :

/Table/Item[Status[contains(@category,'two') and not(contains(., 'DELETE'))]]/Current
har07
  • 88,338
  • 12
  • 84
  • 137