I've been scratching my head trying to figure this out. Basically I am trying io impliment the CSS selector ":only-of-type" in XPath 1. The selector should only pick elements that have no other siblings of the same type.

Its simple enough if I know the type ahead of time. e.g. p[count(../child::p)=1] However, I need it to work for any type of node. The closest I got was this: *[count(../child::name(A)=name(B)])=1] where A is the child node (no problem there, I can just use self:: ) and B is the context node (which I can't see how to reference).

Any ideas? I'm starting to think its not possible.

of-type was discussed in a proposal by James Clark, Henry Thompson, et al to W3C for XSL in 1997 but nothing seems to have come of it.