2

I'm trying to select only the a elements that have a child with a c attribute. So in this case it would be only the first two a elements.

<alpha>
  <a id="1">
    <b c="1"/>
  </a>
  <a id="2">
    <b c="1"/>
  </a>
  <a id="3">
    <b />
  </a>
</alpha>

Any thoughts on how to do this? I've tried the following with no luck:

/alpha/a/b/*[@c]
//a[b/*[@c]]

Thanks in advance for any help!

edit: It was suggested that I consult the solutions posed to this question, however, the problem addressed in that thread is different than mine (involving child elements rather than attributes of child elements) and I haven't been able to extrapolate a solution to my problem from this.

Community
  • 1
  • 1
fyodorfranz
  • 476
  • 8
  • 25
  • possible duplicate of [XPath find all elements with specific child node](http://stackoverflow.com/questions/10881179/xpath-find-all-elements-with-specific-child-node) – Marc B Jul 10 '15 at 21:03

2 Answers2

1

try the following experssion (abbreviated syntax):

//a[*/@c]

Or you can use unabbreviated syntax:

/descendant::a[child::*/attribute::c]
Kachna
  • 2,921
  • 2
  • 20
  • 34
0

This should works as expected: //a/*[@c]

Select any node "//a" with any child "/*" with attribute c "[@c]".