jessa revilla
jessa revilla

Reputation: 33

XPath for node based on the value of another node?

Below is my XML:

<record>
  <f id="7">South East Asia</f>
  <f id="8">Binondo</f>
  <f id="10">3098</f>
  <f id="11">Manila, Philippines</f>
  <f id="27">Commercial</f>
  <f id="22">Dela Cruz, Anna</f>
  <f id="28">D572307</f>
</record>

I want to create an XPath that will return Dela Cruz Anna if record has a f with and id of 3098.

Upvotes: 1

Views: 25

Answers (1)

kjhughes
kjhughes

Reputation: 111491

This XPath,

//record[f[@id=10]="3098"]/f[@id="22"]/text()

will select the text of all f elements with id attribute values of 22 within all record elements with an f element that has an id attribute value of 3098,

Dela Cruz, Anna

as requested.

Upvotes: 1

Related Questions