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


Golang Node.NodeType方法代码示例

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


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

// ShouldStrip evaluates the strip-space, preserve-space, and xml:space rules
// and returns true if a node is a whitespace-only text node that should
// be stripped.
func (context *ExecutionContext) ShouldStrip(xmlNode xml.Node) bool {
	if xmlNode.NodeType() != xml.XML_TEXT_NODE {
		return false
	}
	if !IsBlank(xmlNode) {
		return false
	}
	//do we have a match in strip-space?
	elem := xmlNode.Parent().Name()
	ns := xmlNode.Parent().Namespace()
	for _, pat := range context.Style.StripSpace {
		if pat == elem {
			return true
		}
		if pat == "*" {
			return true
		}
		if strings.Contains(pat, ":") {
			uri, name := context.ResolveQName(pat)
			if uri == ns {
				if name == elem || name == "*" {
					return true
				}
			}
		}
	}
	//do we have a match in preserve-space?
	//resolve conflicts by priority (QName, ns:*, *)
	//return a value
	return false
}
开发者ID:xet7,项目名称:ratago,代码行数:34,代码来源:context.go

示例3: IsBlank

// Returns true if the node is a whitespace-only text node
func IsBlank(xmlnode xml.Node) bool {
	if xmlnode.NodeType() == xml.XML_TEXT_NODE || xmlnode.NodeType() == xml.XML_CDATA_SECTION_NODE {
		content := xmlnode.Content()
		if content == "" || strings.TrimSpace(content) == "" {
			return true
		}
	}
	return false
}
开发者ID:xet7,项目名称:ratago,代码行数:10,代码来源:stylesheet.go

示例4: 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

示例5: processDefaultRule

func (style *Stylesheet) processDefaultRule(node xml.Node, context *ExecutionContext) {
	//default for DOCUMENT, ELEMENT
	children := context.ChildrenOf(node)
	total := len(children)
	for i, cur := range children {
		context.XPathContext.SetContextPosition(i+1, total)
		style.processNode(cur, context, nil)
	}
	//default for CDATA, TEXT, ATTR is copy as text
	if node.NodeType() == xml.XML_TEXT_NODE {
		if context.ShouldStrip(node) {
			return
		}
		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)
		}
	}
	//default for namespace declaration is copy to output document
}
开发者ID:xet7,项目名称:ratago,代码行数:23,代码来源:stylesheet.go

示例6: Apply


//.........这里部分代码省略.........
					a.Apply(node, context)
				}
			}
		}
		for _, c := range i.Children {
			c.Apply(node, context)
		}
	case "fallback":
		for _, c := range i.Children {
			c.Apply(node, context)
		}
	case "otherwise":
		for _, c := range i.Children {
			c.Apply(node, context)
		}

	case "choose":
		for _, c := range i.Children {
			inst := c.(*XsltInstruction)
			if inst.Node.Name() == "when" {
				xp := xpath.Compile(inst.Node.Attr("test"))
				if context.EvalXPathAsBoolean(node, xp) {
					for _, wc := range inst.Children {
						wc.Apply(node, context)
					}
					break
				}
			} else {
				inst.Apply(node, context)
			}
		}
	case "copy":
		//i.copyToOutput(cur, context, false)
		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.Name()
			r := context.Output.CreatePINode(name, node.Content())
			context.OutputNode.AddChild(r)
		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]
开发者ID:xet7,项目名称:ratago,代码行数:67,代码来源:instruction.go

示例7: 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

示例8: 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.NodeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。