An open API service indexing awesome lists of open source software.

https://github.com/featurist/css-to-xpath

Convert CSS selectors to XPaths, in JavaScript
https://github.com/featurist/css-to-xpath

Last synced: about 2 months ago
JSON representation

Convert CSS selectors to XPaths, in JavaScript

Awesome Lists containing this project

README

        

# css-to-xpath

Converts [CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors) to their XPath equivalents.

[![Build Status](https://secure.travis-ci.org/featurist/css-to-xpath.png?branch=master)](http://travis-ci.org/featurist/css-to-xpath)

### Usage

```js
var cssToXPath = require('css-to-xpath');

cssToXPath('p:not(:has(a.x))');
```
...returns the string:
```
.//p[not(.//a[contains(concat(' ', normalize-space(./@class), ' '), ' x ')])]
```

Or if you want to continue building the XPath with xpath-builder:
```js
var cssToXPath = require('css-to-xpath');

var xpathBuilderObject = cssToXPath.parse('p:not(:has(a.x))');
xpathBuilderObject = xpathBuilderObject.where(cssToXPath.xPathBuilder.text().equals('Some Text Content'));

// And get the XPath string
xpathBuilderObject.toXPath();
```

### How?

css-to-xpath parses css selectors using [bo-selector](https://github.com/featurist/bo-selector) and turns them into xpaths using [xpath-builder](https://github.com/featurist/xpath-builder)

### Install

npm install css-to-xpath

### License

BSD