Skip to content

feat: add xpath(xpathStr, xmlStr) CEL function#153

Merged
moshloop merged 3 commits intomainfrom
copilot/add-xpath-cel-function
Apr 9, 2026
Merged

feat: add xpath(xpathStr, xmlStr) CEL function#153
moshloop merged 3 commits intomainfrom
copilot/add-xpath-cel-function

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 9, 2026

Adds XPath 1.0 evaluation support to the CEL expression engine, consistent with the existing jmespath, jsonpath, and jq functions.

Changes

  • coll/json.goXPath(xpathStr, xmlStr string) ([]string, error) core implementation via github.com/antchfx/xmlquery; always returns a []string of text contents for all matching nodes (empty slice for no matches)
  • funcs/coll_gen.go – CEL binding collXPathGen with signature xpath(string, string) → dyn
  • funcs/cel_exports.go – registers collXPathGen in CelEnvOption
  • funcs/coll.go – exposes xpath for Go template use alongside jmespath/jsonpath

Usage

xpath('//name/text()', '<root><name>Alice</name></root>').first()  // "Alice"
xpath('//item/@id', '<root><item id="42"/></root>').first()         // "42"
xpath('//items/item', xml)                                          // ["a", "b", "c"] for multiple matches
xpath('//missing', '<root/>')                                       // []

Copilot AI and others added 2 commits April 9, 2026 11:19
@moshloop
Copy link
Copy Markdown
Member

moshloop commented Apr 9, 2026

@copilot xpath should always return a list, use xpath('//item/@id', '<root><item id="42"/></root>').first()

Copy link
Copy Markdown
Author

Copilot AI commented Apr 9, 2026

@copilot xpath should always return a list, use xpath('//item/@id', '<root><item id="42"/></root>').first()

Done in 58327ce. xpath now always returns []string, so callers can use .first() for a single value:

xpath('//item/@id', '<root><item id="42"/></root>').first()  // "42"
xpath('//item/@id', '<root><item id="1"/><item id="2"/></root>')  // ["1", "2"]

Copilot AI requested a review from moshloop April 9, 2026 15:24
@moshloop moshloop enabled auto-merge (squash) April 9, 2026 15:28
@moshloop moshloop merged commit de89081 into main Apr 9, 2026
3 checks passed
@moshloop moshloop deleted the copilot/add-xpath-cel-function branch April 9, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants