diff --git a/build.go b/build.go index 45ae702..b03afe6 100644 --- a/build.go +++ b/build.go @@ -341,6 +341,12 @@ func (b *builder) processFunction(root *functionNode, props *builderProp) (query var qyOutput query switch root.FuncName { + case "lower-case": + arg, err := b.processNode(root.Args[0], flagsEnum.None, props) + if err != nil { + return nil, err + } + qyOutput = &functionQuery{Input: arg, Func: lowerCaseFunc} case "starts-with": arg1, err := b.processNode(root.Args[0], flagsEnum.None, props) if err != nil { diff --git a/func.go b/func.go index 4131bfd..65386f0 100644 --- a/func.go +++ b/func.go @@ -645,3 +645,9 @@ func stringJoinFunc(arg1 query) func(query, iterator) interface{} { return strings.Join(parts, separator) } } + +// lower-case is XPATH function that converts a string to lower case. +func lowerCaseFunc(q query, t iterator) interface{} { + v := functionArgs(q).Evaluate(t) + return strings.ToLower(asString(t, v)) +} diff --git a/xpath_function_test.go b/xpath_function_test.go index aed0824..06687ae 100644 --- a/xpath_function_test.go +++ b/xpath_function_test.go @@ -231,6 +231,13 @@ func Test_func_normalize_space(t *testing.T) { test_xpath_eval(t, book_example, `normalize-space(//book[1]/title)`, "Everyday Italian") } +func Test_func_lower_case(t *testing.T) { + test_xpath_eval(t, empty_example, `lower-case("ABc!D")`, "abc!d") + test_xpath_count(t, employee_example, `//name[@from="ca"]`, 0) + test_xpath_elements(t, employee_example, `//name[lower-case(@from) = "ca"]`, 9) + //test_xpath_eval(t, employee_example, `//employee/name/lower-case(text())`, "opal kole", "max miller", "beccaa moss") +} + func Benchmark_NormalizeSpaceFunc(b *testing.B) { b.ReportAllocs() const strForNormalization = "\t \rloooooooonnnnnnngggggggg \r \n tes \u00a0 t strinĀ \n\n \r g "