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


Golang Node.Content方法代码示例

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


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

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

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

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


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