{"id":15713704,"url":"https://github.com/naqvis/crystal-xpath2","last_synced_at":"2025-10-09T06:50:28.247Z","repository":{"id":88081896,"uuid":"260514182","full_name":"naqvis/crystal-xpath2","owner":"naqvis","description":"XPath implemenation in Pure Crystal","archived":false,"fork":false,"pushed_at":"2021-04-04T16:32:39.000Z","size":42,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-12T22:55:06.052Z","etag":null,"topics":["crystal","crystal-lang","crystal-language","crystal-shard","xpath","xpath-api","xpath2"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naqvis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-01T17:08:33.000Z","updated_at":"2022-10-12T23:28:43.000Z","dependencies_parsed_at":"2023-05-18T05:00:32.428Z","dependency_job_id":null,"html_url":"https://github.com/naqvis/crystal-xpath2","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/naqvis/crystal-xpath2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fcrystal-xpath2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fcrystal-xpath2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fcrystal-xpath2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fcrystal-xpath2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naqvis","download_url":"https://codeload.github.com/naqvis/crystal-xpath2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fcrystal-xpath2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000859,"owners_count":26082951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","crystal-lang","crystal-language","crystal-shard","xpath","xpath-api","xpath2"],"created_at":"2024-10-03T21:33:00.473Z","updated_at":"2025-10-09T06:50:28.219Z","avatar_url":"https://github.com/naqvis.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Crystal XPath2\n![CI](https://github.com/naqvis/crystal-xpath2/workflows/CI/badge.svg)\n[![GitHub release](https://img.shields.io/github/release/naqvis/crystal-xpath2.svg)](https://github.com/naqvis/crystal-xpath2/releases)\n[![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://naqvis.github.io/crystal-xpath2/)\n\n**Crystal XPath2** Shard provide XPath implementation in **Pure Crystal**. Performs the compilation of XPath expression and provides mechanism to select/evaluate nodes from HTML or other documents using XPath expression\n\nSupported Features\n===\n\n#### The basic XPath patterns.\n\n\u003e The basic XPath patterns cover 90% of the cases that most stylesheets will need.\n\n- `node` : Selects all child elements with node Name of node.\n\n- `*` : Selects all child elements.\n\n- `@attr` : Selects the attribute attr.\n\n- `@*` : Selects all attributes.\n\n- `node()` : Matches an org.w3c.dom.Node.\n\n- `text()` : Matches a org.w3c.dom.Text node.\n\n- `comment()` : Matches a comment.\n\n- `.` : Selects the current node.\n\n- `..` : Selects the parent of current node.\n\n- `/` : Selects the document node.\n\n- `a[expr]` : Select only those nodes matching a which also satisfy the expression expr.\n\n- `a[n]` : Selects the nth matching node matching a When a filter's expression is a number, XPath selects based on position.\n\n- `a/b` : For each node matching a, add the nodes matching b to the result.\n\n- `a//b` : For each node matching a, add the descendant nodes matching b to the result.\n\n- `//b` : Returns elements in the entire document matching b.\n\n- `a|b` : All nodes matching a or b, union operation(not boolean or).\n\n- `(a, b, c)` : Evaluates each of its operands and concatenates the resulting sequences, in order, into a single result sequence\n\n\n#### Node Axes\n\n- `child::*` : The child axis selects children of the current node.\n\n- `descendant::*` : The descendant axis selects descendants of the current node. It is equivalent to `\"//\"`.\n\n- `descendant-or-self::*` : Selects descendants including the current node.\n\n- `attribute::*` : Selects attributes of the current element. It is equivalent to `@*`\n\n- `following-sibling::*` : Selects nodes after the current node.\n\n- `preceding-sibling::*` : Selects nodes before the current node.\n\n- `following::*` : Selects the first matching node following in document order, excluding descendants.\n\n- `preceding::*` : Selects the first matching node preceding in document order, excluding ancestors.\n\n- `parent::*` : Selects the parent if it matches. The `\"..\"` pattern from the core is equivalent to 'parent::node()'.\n\n- `ancestor::*` : Selects matching ancestors.\n\n- `ancestor-or-self::*` : Selects ancestors including the current node.\n\n- `self::*` : Selects the current node. `'.'` is equivalent to `\"self::node()\"`.\n\n#### Expressions\n\n Shard supports three types: number, boolean, string.\n\n- `path` : Selects nodes based on the path.\n\n- `a = b` : Standard comparisons.\n\n    * a `=` b\t    `true` if a equals b.\n    * a `!=` b\t`true` if a is not equal to b.\n    * a `\u003c` b\t    `true` if a is less than b.\n    * a `\u003c=` b\t`true` if a is less than or equal to b.\n    * a `\u003e` b\t    `true` if a is greater than b.\n    * a `\u003e=` b\t`true` if a is greater than or equal to b.\n\n- `a + b` : Arithmetic expressions.\n\n    * `- a`\tUnary minus\n    * a `+` b\tAdd\n    * a `-` b\tSubstract\n    * a `*` b\tMultiply\n    * a `div` b\tDivide\n    * a `mod` b\tFloating point mod, like Java.\n\n- `a or b` : Boolean `or` operation.\n\n- `a and b` : Boolean `and` operation.\n\n- `(expr)` : Parenthesized expressions.\n\n- `fun(arg1, ..., argn)` : Function calls:\n\n| Function | Supported |\n| --- | --- |\n`boolean()`| ✓ |\n`ceiling()`| ✓ |\n`choose()`| ✗ |\n`concat()`| ✓ |\n`contains()`| ✓ |\n`count()`| ✓ |\n`current()`| ✗ |\n`document()`| ✗ |\n`element-available()`| ✗ |\n`ends-with()`| ✓ |\n`false()`| ✓ |\n`floor()`| ✓ |\n`format-number()`| ✗ |\n`function-available()`| ✗ |\n`generate-id()`| ✗ |\n`id()`| ✗ |\n`key()`| ✗ |\n`lang()`| ✗ |\n`last()`| ✓ |\n`local-name()`| ✓ |\n`name()`| ✓ |\n`namespace-uri()`| ✓ |\n`normalize-space()`| ✓ |\n`not()`| ✓ |\n`number()`| ✓ |\n`position()`| ✓ |\n`replace()`| ✓ |\n`reverse()`| ✓ |\n`round()`| ✓ |\n`starts-with()`| ✓ |\n`string()`| ✓ |\n`string-length()`| ✓ |\n`substring()`| ✓ |\n`substring-after()`| ✓ |\n`substring-before()`| ✓ |\n`sum()`| ✓ |\n`system-property()`| ✗ |\n`translate()`| ✓ |\n`true()`| ✓ |\n`unparsed-entity-url()` | ✗ |\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     xpath2:\n       github: naqvis/crystal-xpath2\n   ```\n\n2. Run `shards install`\n\n## Usage\n\nrefer to `spec` for usage examples or refer to [Crystal HTML5](https://github.com/naqvis/crystal-html5) and [JSON XPath](https://github.com/naqvis/json-xpath) for implementation details.\n\n## Development\n\nTo run all tests:\n\n```\ncrystal spec\n```\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/naqvis/crystal-xpath2/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Ali Naqvi](https://github.com/naqvis) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaqvis%2Fcrystal-xpath2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaqvis%2Fcrystal-xpath2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaqvis%2Fcrystal-xpath2/lists"}