当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.EvalXPath方法代码示例

本文整理汇总了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)
	}
}
开发者ID:jbowtie,项目名称:ratago,代码行数:34,代码来源:stylesheet.go

示例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)
}
开发者ID:jbowtie,项目名称:ratago,代码行数:64,代码来源:instruction.go


注:本文中的github.com/jbowtie/gokogiri/xml.Node.EvalXPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。