Skip to content

Commit 03595ea

Browse files
author
Denys Smirnov
committed
implement local-name() function
1 parent 1eb2707 commit 03595ea

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

build.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ func (b *builder) processFunctionNode(root *functionNode) (query, error) {
233233
return nil, err
234234
}
235235
qyOutput = &functionQuery{Input: argQuery, Func: notFunc}
236-
case "name":
236+
case "name", "local-name":
237237
inp := b.firstInput
238238
if len(root.Args) > 1 {
239-
return nil, errors.New("xpath: name function must have at most one parameter")
239+
return nil, fmt.Errorf("xpath: %s function must have at most one parameter", root.FuncName)
240240
}
241241
if len(root.Args) == 1 {
242242
argQuery, err := b.processNode(root.Args[0])
@@ -245,7 +245,14 @@ func (b *builder) processFunctionNode(root *functionNode) (query, error) {
245245
}
246246
inp = argQuery
247247
}
248-
qyOutput = &functionQuery{Input: inp, Func: nameFunc}
248+
f := &functionQuery{Input: inp}
249+
switch root.FuncName {
250+
case "name":
251+
f.Func = nameFunc
252+
case "local-name":
253+
f.Func = localNameFunc
254+
}
255+
qyOutput = f
249256
case "last":
250257
qyOutput = &functionQuery{Input: b.firstInput, Func: lastFunc}
251258
case "position":

func.go

+9
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ func nameFunc(q query, t iterator) interface{} {
103103
return ns + ":" + v.LocalName()
104104
}
105105

106+
// localNameFunc is a XPath functions local-name([node-set]).
107+
func localNameFunc(q query, t iterator) interface{} {
108+
v := q.Select(t)
109+
if v == nil {
110+
return ""
111+
}
112+
return v.LocalName()
113+
}
114+
106115
func asBool(t iterator, v interface{}) bool {
107116
switch v := v.(type) {
108117
case nil:

0 commit comments

Comments
 (0)