getodk / getodk/web-forms

Reverse axes should follow reverse document order

Open
#177 0 comments 0 reactions 0 assignees View on GitHub
@odk/xpath
Dominant language
TypeScript
Stars
38
Forks
22
PR merge metrics
No merged PRs in 30d

Description

From the spec:

> An axis is either a forward axis or a reverse axis. An axis that only ever contains the context node or nodes that are after the context node in [document order](https://www.w3.org/TR/1999/REC-xpath-19991116/#dt-document-order) is a forward axis. An axis that only ever contains the context node or nodes that are before the context node in [document order](https://www.w3.org/TR/1999/REC-xpath-19991116/#dt-document-order) is a reverse axis. Thus, the ancestor, ancestor-or-self, preceding, and preceding-sibling axes are reverse axes; all other axes are forward axes. Since the self axis always contains at most one node, it makes no difference whether it is a forward or reverse axis. The proximity position of a member of a node-set with respect to an axis is defined to be the position of the node in the node-set ordered in document order if the axis is a forward axis and ordered in reverse document order if the axis is a reverse axis. The first position is 1.

I expect following test to pass:

```
it.only('adhoc tests', () => {
const testDocument = xml`


Some content


`;
const evaluator = new Evaluator({rootNode: testDocument});

const actual = evaluator.evaluate(`//bar/ancestor::*[1]/@name`);

expect(actual.stringValue).toBe('first');
})
```

In the current implementation `//bar/ancestor::*[1]` is selecting the `root` node, it should select `foo` node.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the supplied Evaluator test and the implementation that evaluates `//bar/ancestor::*[1]/@name`. Check how reverse-axis results determine proximity position, then verify the expression selects the `foo` node and returns `first` rather than selecting `root`.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.