0
votes

Following is a sample xml.

<library>
    <book id="aaa">
      <title id="bbb">Harry Potter and the Half Blood Prince</title>
      <author id="ccc" ref="zzz"/>
    </book>
    <book id="ddd">
      <title id="eee">Harry Potter and the Philosophers Stone</title>
      <author id="fff" ref="zzz"/>
    </book>
    <author-details id="zzz">
      <firstName id="ggg">Joanne</firstName>
      <lastName id="hhh"/>Rowling</lastName>
    </author-details>
</library>

There are many more books in this example and many author details as well. What I want, is to retrieve all attribute nodes, what ever be the attributes name, with a specified value.
For example, in the above sample I want the xpath to return the following nodes. (all attribute nodes that contain the value of 'zzz', what ever be the attributes name).

  1. ref="zzz" from the first book node.
  2. ref="zzz" from the second book node.
  3. and, id="zzz" from author-details node.

I am writing Java code and want to change the value of the id='zzz' to some other value.

1

1 Answers

2
votes

Well //@* gives you all attribute nodes, add a predicate //@*[. = 'zzz'] and you have all attribute nodes with the value zzz.