diff --git a/build.go b/build.go index a93c8eb..af2b1d2 100644 --- a/build.go +++ b/build.go @@ -208,6 +208,8 @@ func (b *builder) processFilter(root *filterNode, flags flag, props *builderProp switch qyFunc.Input.(type) { case *filterQuery: cond = &lastFuncQuery{Input: qyFunc.Input} + case *groupQuery: + cond = &lastFuncQuery{Input: qyFunc.Input.Clone()} } } } @@ -689,9 +691,7 @@ func (b *builder) processNode(root node, flags flag, props *builderProp) (q quer return } q = &groupQuery{Input: q} - if b.firstInput == nil { - b.firstInput = q - } + b.firstInput = q } b.parseDepth-- return diff --git a/xpath_predicate_test.go b/xpath_predicate_test.go index 30126e1..dd48d37 100644 --- a/xpath_predicate_test.go +++ b/xpath_predicate_test.go @@ -27,7 +27,11 @@ func TestPositions(t *testing.T) { test_xpath_elements(t, employee_example, `//employee[last()]`, 13) test_xpath_elements(t, employee_example, `//employee[position() = last()]`, 13) test_xpath_elements(t, book_example, `//book[@category = "web"][2]`, 25) + test_xpath_elements(t, book_example, `//book[@category = "web"][last()]`, 25) test_xpath_elements(t, book_example, `(//book[@category = "web"])[2]`, 25) + test_xpath_elements(t, book_example, `(//book[@category = "web"])[last()]`, 25) + test_xpath_elements(t, employee_example, `(//employee)[last()]`, 13) + test_xpath_elements(t, book_example, `(//author)[last()]`, 27) } func TestPredicates(t *testing.T) {