xpathify 0.1.0-a1

CSS selector to XPath 1.0 converter.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 43.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 79.4 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • roniemartinez

xpathify

CSS selector to XPath 1.0 converter.

Rust

cargo add xpathify
assert_eq!(xpathify::xpathify("div.item"), "//div[contains(concat(' ',normalize-space(@class),' '),' item ')]");
assert_eq!(xpathify::xpathify(":root > body"), "/body");
assert_eq!(xpathify::xpathify("div,span"), ""); // unsupported selector

Supported syntax

CSS XPath
*, div, .class, #id //*, //div, class containment test, @id equality
a b, a > b, a ~ b, a + b //, /, following-sibling::b, following-sibling::b[1]
[attr], [attr=v] @attr, @attr="v"
[attr^=v], [attr$=v], [attr*=v] starts-with, substring, contains
[attr~=v], [attr|=v] word containment, v or v- prefix
:root, :first-child, :last-child /, sibling absence tests
:nth-child(n), :nth-of-type(n), :first-of-type, :last-of-type positional predicates
:not(s) where s is one class, id, tag or attribute not(...)

Anything else, including selector lists and a combinator inside :not(), returns the empty string.