1

I am using XPath to query a database. I am having trouble trying to return two values. I have a single attribute table which is an XML element called Book. I could find the title of all books but I don't know how to find the title AND year of all books. Below shows Book:

<Book>
<Title></Title>
<Year></Year>
<Author></Author>
</Book>

To find the title of all books I would use:

/book/title.

How would I find the title and the year of all books?

2 Answers 2

1

You can test the self:: axis to select multiple children of Book:

/Book/*[self::Title or self::Year]
Sign up to request clarification or add additional context in comments.

Comments

1

You can use a union:

/book/title | /book/year

Comments

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.