Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theseer/css2xpath
PHP Library to translate CSS selectors into XPath
https://github.com/theseer/css2xpath
Last synced: 3 months ago
JSON representation
PHP Library to translate CSS selectors into XPath
- Host: GitHub
- URL: https://github.com/theseer/css2xpath
- Owner: theseer
- License: bsd-3-clause
- Created: 2017-10-29T20:59:55.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-12T13:22:10.000Z (11 months ago)
- Last Synced: 2024-10-03T10:49:30.984Z (3 months ago)
- Language: PHP
- Size: 21.5 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# CSS2XPath
This is yet another library to translate various CSS selectors to their XPath equivalent.
[![Build Status](https://travis-ci.org/theseer/css2xpath.svg?branch=master)](https://travis-ci.org/theseer/css2xpath)
[![Latest Stable Version](https://img.shields.io/packagist/v/theseer/css2xpath.svg)](https://packagist.org/packages/theseer/css2xpath)## Example
```php
$translator = new TheSeer\CSS2XPath\Translator();
// Will output //*[contains(concat(" ",normalize-space(@class)," ")," note ")]
echo $translator->translate('.note');// Will output //*[@id="me"]
echo $translator->translate('#me');
```## Installation
You can add this library as a local, per-project dependency to your project using Composer:
```
composer require theseer/css2xpath
```## Selectors supported
The following selectors are currently covered:
- #id
- tag#id
- tag #id
- tag
- tag tag
- tag > tag
- tag + tag
- tag ~ tag
- tag, tag
- .classname
- tag.classname
- tag .classname
- tag.classname, tag.classname
- tag.classname tag.classname
- tag.classname > tag.classname
- tag#id + tag > tag
- tag[id]:contains(Selectors)
- tag[attribute][attribute]
- tag[attribute]
- tag[attribute=example]
- tag[attribute^=exa]
- tag[class$=mple]
- tag[attribute*=e]
- tag[attribute|=dialog]
- tag[attribute!=made_up]
- tag[attribute!="made_up"]
- tag[attribute~=example]
- tag:not(.classname)
- tag:contains(selectors)
- tag:nth-child(n)
- tag:nth-child(even)
- tag:nth-child(odd)
- tag:nth-child(3n+8)
- tag:nth-child(2n+1)
- tag:nth-child(3)
- tag:nth-child(4n)
- tag:only-child
- tag:last-child
- tag:first-child
- foo|bar
- tag[attribute^=exa][attribute$=mple]
- tag:enabled
- tag:checked
- tag:disabled
- :empty
- :root