1

I'm using this XPATH query:

xpath.compile("/TEI.2/text/body/div/entry/sense/cit/quote[text()="malta"]") 

I'd like to get the 2nd "quote" node containing "malta". How can I do that?

I have tried:

xpath.compile("/TEI.2/text/body/div/entry/sense/cit/quote[text()="malta" and position()=2]")

as well as

xpath.compile("/TEI.2/text/body/div/entry/sense/cit/quote[text()="malta"][2]") 

These give me an empty result however I'm sure there is a second node.

Thanks!

5
  • The third one doesn't work, I've tried it out again just now. And about the xml, I can't put it over here. Commented Jan 13, 2012 at 11:25
  • Try use normalize-space(text()) Commented Jan 13, 2012 at 11:27
  • just post your xml, you can remove sensitive information ;) Commented Jan 13, 2012 at 11:42
  • Post sample XML which reproduces your issue. Commented Jan 13, 2012 at 11:43
  • It's not clear from the question, perhaps you want (…original xpath query…)[2]. Commented Jan 13, 2012 at 13:29

1 Answer 1

1

Solved it.

I had to add brackets to the expression before the final [2]

I.e.

xpath.compile("(/TEI.2/text/body/div/entry/sense/cit/quote[text()="malta"])[2]") 

Thanks still!

Sign up to request clarification or add additional context in comments.

1 Comment

Krt_Malta, Brackets are only needed if the XPath // pseudo-operator is used -- which in your XPath expression isn't used. Therefore, either you are misleading the readers and you are actually having a different XPath expression, or the XPath engine you are using isn't a compliant XPAth implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.