Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Support for :last/:last-child and other CSS3 selectors which makes sense #9

Open
aight8 opened this issue Jun 23, 2016 · 3 comments
Open

Comments

@aight8
Copy link

aight8 commented Jun 23, 2016

Because it's then configurable without writing custom code

@weierophinney
Copy link
Member

@aight8 Would you be willing to give implementing these features a try?

@Rct567
Copy link

Rct567 commented Apr 23, 2017

Hi, i wrote an improved version for my own use. You can find it (and use it in any way) at: https://pastebin.com/Lt4WS2wz

I have tested it with the following conversions (i have not tested all the xpath results):

'a' => '//a',
'' => '//',
'* > a' => '///a',
'#someid' => '//
[@id='someid']',
'p#someid' => '//p[@id='someid']',
'p a' => '//p//a',
'p a[href]' => '//p//a[@href]',
'a[href="html"]' => '//a[@href='html']',
'a[href!="html"]' => '//a[@href!='html']',
'a[href*='html']' => '//a[contains(@href, 'html')]',
'[href*='html']' => '//[contains(@href, 'html')]',
'[href^='html']' => '//
[starts-with(@href, 'html')]',
'[href$='html']' => '//[@href = substring(@href, string-length(@href) - string-length(@href) +1)]',
'[href~='html']' => '//
[contains(concat(' ', normalize-space(@href), ' '), ' html ')]',
'p > a' => '//p/a',
'p > a[href]' => '//p/a[@href]',
'p a[href]' => '//p//a[@href]',
'> a' => '/a',
':disabled' => '//[@disabled]',
'.hidden' => '//
[contains(concat(' ', normalize-space(@Class), ' '), ' hidden ')]',
'a.hidden[href]' => '//a[contains(concat(' ', normalize-space(@Class), ' '), ' hidden ')][@href]',
'a[href] > .hidden' => '//a[@href]/[contains(concat(' ', normalize-space(@Class), ' '), ' hidden ')]',
'a:not(b[cool])' => '//a[not(b[@cool])]',
'a:not(.cool)' => '//a[not(
[contains(concat(' ', normalize-space(@Class), ' '), ' cool ')])]',
'a:contains(txt)' => '//a[text()[contains(.,'txt')]]'

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-dom; a new issue has been opened at laminas/laminas-dom#5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants