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


Golang Node.Name方法代码示例

本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Name方法的具体用法?Golang Node.Name怎么用?Golang Node.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ThomsonReutersEikon/gokogiri/xml.Node的用法示例。


在下文中一共展示了Node.Name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CompileSingleNode

func CompileSingleNode(node xml.Node) (step CompiledStep) {
	switch node.NodeType() {
	case xml.XML_ELEMENT_NODE:
		ns := node.Namespace()
		// element, extension namespace = extension
		if ns == XSLT_NAMESPACE {
			// element, XSLT namespace = instruction
			switch node.Name() {
			case "variable":
				step = &Variable{Node: node}
			case "param", "with-param":
				step = &Variable{Node: node}
			default:
				step = &XsltInstruction{Name: node.Name(), Node: node}
			}
		} else {
			// element other namespace = LRE
			step = &LiteralResultElement{Node: node}
		}
	// text, CDATA node
	case xml.XML_TEXT_NODE, xml.XML_CDATA_SECTION_NODE:
		if !IsBlank(node) {
			step = &TextOutput{Content: node.Content()}
		}
	}
	return
}
开发者ID:xet7,项目名称:ratago,代码行数:27,代码来源:template.go

示例2: UseCDataSection

func (context *ExecutionContext) UseCDataSection(node xml.Node) bool {
	if node.NodeType() != xml.XML_ELEMENT_NODE {
		return false
	}
	name := node.Name()
	ns := node.Namespace()
	for _, el := range context.Style.CDataElements {
		if el == name {
			return true
		}
		uri, elname := context.ResolveQName(el)
		if uri == ns && name == elname {
			return true
		}
	}
	return false
}
开发者ID:xet7,项目名称:ratago,代码行数:17,代码来源:context.go

示例3: Apply

// Evaluate an instruction and generate output nodes
func (i *XsltInstruction) Apply(node xml.Node, context *ExecutionContext) {
	//push context if children to apply!
	switch i.Name {
	case "apply-templates":
		scope := i.Node.Attr("select")
		mode := i.Node.Attr("mode")
		// #current is a 2.0 keyword
		if mode != context.Mode && mode != "#current" {
			context.Mode = mode
		}
		// TODO: determine with-params at compile time
		var params []*Variable
		for _, cur := range i.Children {
			switch p := cur.(type) {
			case *Variable:
				if IsXsltName(p.Node, "with-param") {
					p.Apply(node, context)
					params = append(params, p)
				}
			}
		}
		// By default, scope is children of current node
		if scope == "" {
			children := context.ChildrenOf(node)
			if i.sorting != nil {
				i.Sort(children, context)
			}
			total := len(children)
			oldpos, oldtotal := context.XPathContext.GetContextPosition()
			oldcurr := context.Current
			for i, cur := range children {
				context.XPathContext.SetContextPosition(i+1, total)
				//processNode will update Context.Current whenever a template is invoked
				context.Style.processNode(cur, context, params)
			}
			context.XPathContext.SetContextPosition(oldpos, oldtotal)
			context.Current = oldcurr
			return
		}
		context.RegisterXPathNamespaces(i.Node)
		e := xpath.Compile(scope)
		// TODO: ensure we apply strip-space if required
		nodes, err := context.EvalXPathAsNodeset(node, e)
		if err != nil {
			fmt.Println("apply-templates @select", err)
		}
		if i.sorting != nil {
			i.Sort(nodes, context)
		}
		total := len(nodes)
		oldpos, oldtotal := context.XPathContext.GetContextPosition()
		oldcurr := context.Current
		for i, cur := range nodes {
			context.XPathContext.SetContextPosition(i+1, total)
			context.Style.processNode(cur, context, params)
		}
		context.XPathContext.SetContextPosition(oldpos, oldtotal)
		context.Current = oldcurr
	case "number":
		i.numbering(node, context)

	case "text":
		disableEscaping := i.Node.Attr("disable-output-escaping") == "yes"

		content := i.Node.Content()
		//don't bother creating a text node for an empty string
		if content != "" {
			r := context.Output.CreateTextNode(content)
			if disableEscaping {
				r.DisableOutputEscaping()
			}
			context.OutputNode.AddChild(r)
		}

	case "call-template":
		name := i.Node.Attr("name")
		t, ok := context.Style.NamedTemplates[name]
		if ok && t != nil {
			// TODO: determine with-params at compile time
			var params []*Variable
			for _, cur := range i.Children {
				switch p := cur.(type) {
				case *Variable:
					if IsXsltName(p.Node, "with-param") {
						p.Apply(node, context)
						params = append(params, p)
					}
				}
			}
			t.Apply(node, context, params)
		}

	case "element":
		ename := i.Node.Attr("name")
		if strings.ContainsRune(ename, '{') {
			ename = evalAVT(ename, node, context)
		}
		r := context.Output.CreateElementNode(ename)
		ns := i.Node.Attr("namespace")
//.........这里部分代码省略.........
开发者ID:xet7,项目名称:ratago,代码行数:101,代码来源:instruction.go

示例4: copyToOutput

func (i *XsltInstruction) copyToOutput(node xml.Node, context *ExecutionContext, recursive bool) {
	switch node.NodeType() {
	case xml.XML_TEXT_NODE:
		if context.UseCDataSection(context.OutputNode) {
			r := context.Output.CreateCDataNode(node.Content())
			context.OutputNode.AddChild(r)
		} else {
			r := context.Output.CreateTextNode(node.Content())
			context.OutputNode.AddChild(r)
		}
	case xml.XML_ATTRIBUTE_NODE:
		aname := node.Name()
		ahref := node.Namespace()
		val := node.Content()
		if ahref == "" {
			context.OutputNode.SetAttr(aname, val)
		} else {
			context.OutputNode.SetNsAttr(ahref, aname, val)
		}
	case xml.XML_COMMENT_NODE:
		r := context.Output.CreateCommentNode(node.Content())
		context.OutputNode.AddChild(r)
	case xml.XML_PI_NODE:
		name := node.Attr("name")
		r := context.Output.CreatePINode(name, node.Content())
		context.OutputNode.AddChild(r)
	case xml.XML_NAMESPACE_DECL:
		//in theory this should work
		//in practice it's a little complicated due to the fact
		//that namespace declarations don't map to the node type
		//very well
		//will need to revisit
		//context.OutputNode.DeclareNamespace(node.Name(), node.Content())
	case xml.XML_ELEMENT_NODE:
		aname := node.Name()
		r := context.Output.CreateElementNode(aname)
		context.OutputNode.AddChild(r)
		ns := node.Namespace()
		if ns != "" {
			//TODO: search through namespaces in-scope
			prefix, _ := context.Style.NamespaceMapping[ns]
			r.SetNamespace(prefix, ns)
		} else {
			//may need to explicitly reset to empty namespace
			def := context.DefaultNamespace(context.OutputNode)
			if def != "" {
				r.SetNamespace("", "")
			}
		}

		//copy namespace declarations
		for _, decl := range node.DeclaredNamespaces() {
			r.DeclareNamespace(decl.Prefix, decl.Uri)
		}

		old := context.OutputNode
		context.OutputNode = r
		if recursive {
			//copy attributes
			for _, attr := range node.Attributes() {
				i.copyToOutput(attr, context, recursive)
			}
			for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
				i.copyToOutput(cur, context, recursive)
			}
		}
		context.OutputNode = old
	case xml.XML_DOCUMENT_NODE:
		if recursive {
			for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
				i.copyToOutput(cur, context, recursive)
			}
		}
	}
}
开发者ID:xet7,项目名称:ratago,代码行数:75,代码来源:instruction.go

示例5: 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:xet7,项目名称:ratago,代码行数:64,代码来源:instruction.go

示例6: IsXsltName

// Returns true if the node is in the XSLT namespace
func IsXsltName(xmlnode xml.Node, name string) bool {
	if xmlnode.Name() == name && xmlnode.Namespace() == XSLT_NAMESPACE {
		return true
	}
	return false
}
开发者ID:xet7,项目名称:ratago,代码行数:7,代码来源:stylesheet.go

示例7: LookupTemplate

// If there is no matching template, nil is returned.
func (style *Stylesheet) LookupTemplate(node xml.Node, mode string, context *ExecutionContext) (template *Template) {
	name := node.Name()
	if node.NodeType() == xml.XML_DOCUMENT_NODE {
		name = "/"
	}
	found := new(list.List)
	l := style.ElementMatches[name]
	if l != nil {
		for i := l.Front(); i != nil; i = i.Next() {
			c := i.Value.(*CompiledMatch)
			if c.EvalMatch(node, mode, context) {
				insertByPriority(found, c)
				break
			}
		}
	}
	l = style.ElementMatches["*"]
	if l != nil {
		for i := l.Front(); i != nil; i = i.Next() {
			c := i.Value.(*CompiledMatch)
			if c.EvalMatch(node, mode, context) {
				insertByPriority(found, c)
				break
			}
		}
	}
	l = style.AttrMatches[name]
	if l != nil {
		for i := l.Front(); i != nil; i = i.Next() {
			c := i.Value.(*CompiledMatch)
			if c.EvalMatch(node, mode, context) {
				insertByPriority(found, c)
				break
			}
		}
	}
	l = style.AttrMatches["*"]
	if l != nil {
		for i := l.Front(); i != nil; i = i.Next() {
			c := i.Value.(*CompiledMatch)
			if c.EvalMatch(node, mode, context) {
				insertByPriority(found, c)
				break
			}
		}
	}
	//TODO: review order in which we consult generic matches
	for i := style.IdKeyMatches.Front(); i != nil; i = i.Next() {
		c := i.Value.(*CompiledMatch)
		if c.EvalMatch(node, mode, context) {
			insertByPriority(found, c)
			break
		}
	}
	for i := style.NodeMatches.Front(); i != nil; i = i.Next() {
		c := i.Value.(*CompiledMatch)
		if c.EvalMatch(node, mode, context) {
			insertByPriority(found, c)
			break
		}
	}
	for i := style.TextMatches.Front(); i != nil; i = i.Next() {
		c := i.Value.(*CompiledMatch)
		if c.EvalMatch(node, mode, context) {
			insertByPriority(found, c)
			break
		}
	}
	for i := style.PIMatches.Front(); i != nil; i = i.Next() {
		c := i.Value.(*CompiledMatch)
		if c.EvalMatch(node, mode, context) {
			insertByPriority(found, c)
			break
		}
	}
	for i := style.CommentMatches.Front(); i != nil; i = i.Next() {
		c := i.Value.(*CompiledMatch)
		if c.EvalMatch(node, mode, context) {
			insertByPriority(found, c)
			break
		}
	}

	// if there's a match at this import precedence, return
	// the one with the highest priority
	f := found.Front()
	if f != nil {
		template = f.Value.(*CompiledMatch).Template
		return
	}

	// no match at this import precedence,
	//consult the imported stylesheets
	for i := style.Imports.Front(); i != nil; i = i.Next() {
		s := i.Value.(*Stylesheet)
		t := s.LookupTemplate(node, mode, context)
		if t != nil {
			return t
		}
//.........这里部分代码省略.........
开发者ID:xet7,项目名称:ratago,代码行数:101,代码来源:stylesheet.go


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