954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

XPath / CSS selector query

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.

kissmyawesome
Newbie Poster
4 posts since Dec 2008
Reputation Points: 12
Solved Threads: 1
 

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.

fpmurphy
Junior Poster
147 posts since Oct 2008
Reputation Points: 22
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You