本文整理汇总了Golang中github.com/jbowtie/gokogiri/xml.Node.EvalXPath方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.EvalXPath方法的具体用法?Golang Node.EvalXPath怎么用?Golang Node.EvalXPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbowtie/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.EvalXPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: populateKeys
func (style *Stylesheet) populateKeys(node xml.Node, context *ExecutionContext) {
for _, key := range style.Keys {
//see if the current node matches
matches := CompileMatch(key.match, nil)
hasMatch := false
for _, m := range matches {
if m.EvalMatch(node, "", context) {
hasMatch = true
break
}
}
if !hasMatch {
continue
}
lookupkey, _ := node.EvalXPath(key.use, context)
lookup := ""
switch lk := lookupkey.(type) {
case []xml.Node:
if len(lk) == 0 {
continue
}
lookup = lk[0].String()
case string:
lookup = lk
default:
lookup = fmt.Sprintf("%v", lk)
}
key.nodes[lookup] = append(key.nodes[lookup], node)
}
children := context.ChildrenOf(node)
for _, cur := range children {
style.populateKeys(cur, context)
}
}
示例2: numbering
func (i *XsltInstruction) numbering(node xml.Node, context *ExecutionContext) {
//level
level := i.Node.Attr("level")
if level == "" {
level = "single"
}
//count
count := i.Node.Attr("count")
if count == "" {
//TODO: qname (should match NS as well
count = node.Name()
}
//from
from := i.Node.Attr("from")
//value
valattr := i.Node.Attr("value")
//format
format := i.Node.Attr("format")
if format == "" {
format = "1"
}
//lang
//letter-value
//grouping-seperator
//grouping-size
var numbers []int
//if value, just use that!
if valattr != "" {
v, _ := node.EvalXPath(valattr, context)
if v == nil {
numbers = append(numbers, 0)
} else {
numbers = append(numbers, int(v.(float64)))
}
} else {
target := findTarget(node, count)
v := countNodes(level, target, count, from)
numbers = append(numbers, v)
if level == "multiple" {
for cur := target.Parent(); cur != nil; cur = cur.Parent() {
v = countNodes(level, cur, count, from)
if v > 0 {
numbers = append(numbers, v)
}
}
if len(numbers) > 1 {
for i, j := 0, len(numbers)-1; i < j; i, j = i+1, j-1 {
numbers[i], numbers[j] = numbers[j], numbers[i]
}
}
}
}
// level = multiple
// count preceding siblings AT EACH LEVEL
// format using the format string
outtxt := formatNumbers(numbers, format)
r := context.Output.CreateTextNode(outtxt)
context.OutputNode.AddChild(r)
}