本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node类的典型用法代码示例。如果您正苦于以下问题:Golang Node类的具体用法?Golang Node怎么用?Golang Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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:xet7,项目名称:ratago,代码行数:34,代码来源:stylesheet.go
示例3: Compile
func (e *LiteralResultElement) Compile(node xml.Node) {
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
res := CompileSingleNode(cur)
if res != nil {
res.Compile(cur)
e.Children = append(e.Children, res)
}
}
}
开发者ID:xet7,项目名称:ratago,代码行数:9,代码来源:template.go
示例4: CompileContent
func (template *Template) CompileContent(node xml.Node) {
//parse the content and register the match pattern
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
res := CompileSingleNode(cur)
if res != nil {
res.Compile(cur)
template.AddChild(res)
}
}
}
开发者ID:xet7,项目名称:ratago,代码行数:10,代码来源:template.go
示例5: DefaultNamespace
// Determine the default namespace currently defined in scope
func (context *ExecutionContext) DefaultNamespace(node xml.Node) string {
//get the list of in-scope namespaces
// any with a null prefix? return that
decl := node.DeclaredNamespaces()
for _, d := range decl {
if d.Prefix == "" {
return d.Uri
}
}
return ""
}
开发者ID:xet7,项目名称:ratago,代码行数:12,代码来源:context.go
示例6: ChildrenOf
// ChildrenOf returns the node children, ignoring any whitespace-only text nodes that
// are stripped by strip-space or xml:space
func (context *ExecutionContext) ChildrenOf(node xml.Node) (children []xml.Node) {
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
//don't count stripped nodes
if context.ShouldStrip(cur) {
continue
}
children = append(children, cur)
}
return
}
开发者ID:xet7,项目名称:ratago,代码行数:13,代码来源:context.go
示例7: Compile
// Compile the instruction.
//
// TODO: we should validate the structure during this step
func (i *XsltInstruction) Compile(node xml.Node) {
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
res := CompileSingleNode(cur)
if cur.Name() == "sort" && cur.Namespace() == XSLT_NAMESPACE {
i.sorting = append(i.sorting, compileSortFunction(res.(*XsltInstruction)))
continue
}
if res != nil {
res.Compile(cur)
i.Children = append(i.Children, res)
}
}
}
开发者ID:xet7,项目名称:ratago,代码行数:16,代码来源:instruction.go
示例8: DeclareStylesheetNamespacesIfRoot
// Propogate namespaces to the root of the output document
func (context *ExecutionContext) DeclareStylesheetNamespacesIfRoot(node xml.Node) {
if context.OutputNode.NodeType() != xml.XML_DOCUMENT_NODE {
return
}
//add all namespace declarations to r
for uri, prefix := range context.Style.NamespaceMapping {
if uri != XSLT_NAMESPACE {
//these don't actually change if there is no alias
_, uri = ResolveAlias(context.Style, prefix, uri)
if !context.Style.IsExcluded(prefix) {
node.DeclareNamespace(prefix, uri)
}
}
}
}
开发者ID:xet7,项目名称:ratago,代码行数:16,代码来源:context.go
示例9: EvalXPathAsNodeset
func (context *ExecutionContext) EvalXPathAsNodeset(xmlNode xml.Node, data interface{}) (result xml.Nodeset, err error) {
_, err = context.EvalXPath(xmlNode, data)
if err != nil {
return nil, err
}
nodePtrs, err := context.XPathContext.ResultAsNodeset()
if err != nil {
return nil, err
}
var output xml.Nodeset
for _, nodePtr := range nodePtrs {
output = append(output, xml.NewNode(nodePtr, xmlNode.MyDocument()))
}
result = output
return
}
开发者ID:xet7,项目名称:ratago,代码行数:16,代码来源:context.go
示例10: EvalXPath
func (context *ExecutionContext) EvalXPath(xmlNode xml.Node, data interface{}) (result interface{}, err error) {
switch data := data.(type) {
case string:
if xpathExpr := xpath.Compile(data); xpathExpr != nil {
defer xpathExpr.Free()
result, err = context.EvalXPath(xmlNode, xpathExpr)
} else {
err = errors.New("cannot compile xpath: " + data)
}
case []byte:
result, err = context.EvalXPath(xmlNode, string(data))
case *xpath.Expression:
xpathCtx := context.XPathContext
xpathCtx.SetResolver(context)
err := xpathCtx.Evaluate(xmlNode.NodePtr(), data)
if err != nil {
return nil, err
}
rt := xpathCtx.ReturnType()
switch rt {
case xpath.XPATH_NODESET, xpath.XPATH_XSLT_TREE:
nodePtrs, err := xpathCtx.ResultAsNodeset()
if err != nil {
return nil, err
}
var output []xml.Node
for _, nodePtr := range nodePtrs {
output = append(output, xml.NewNode(nodePtr, xmlNode.MyDocument()))
}
result = output
case xpath.XPATH_NUMBER:
result, err = xpathCtx.ResultAsNumber()
case xpath.XPATH_BOOLEAN:
result, err = xpathCtx.ResultAsBoolean()
default:
result, err = xpathCtx.ResultAsString()
}
default:
err = errors.New("Strange type passed to ExecutionContext.EvalXPath")
}
return
}
开发者ID:xet7,项目名称:ratago,代码行数:42,代码来源:context.go
示例11: 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
示例12: 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
示例13: 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
示例14: ParseTemplate
// ParseTemplate parses and compiles the xsl:template elements.
func (style *Stylesheet) ParseTemplate(node xml.Node) {
//add to template list of stylesheet
//parse mode, match, name, priority
mode := node.Attr("mode")
name := node.Attr("name")
match := node.Attr("match")
priority := node.Attr("priority")
p := 0.0
if priority != "" {
p, _ = strconv.ParseFloat(priority, 64)
}
// TODO: validate the name (duplicate should raise error)
template := &Template{Match: match, Mode: mode, Name: name, Priority: p, Node: node}
template.CompileContent(node)
// compile pattern
style.compilePattern(template, priority)
}
开发者ID:xet7,项目名称:ratago,代码行数:21,代码来源:stylesheet.go
示例15: 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
示例16: 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
示例17: RegisterAttributeSet
func (style *Stylesheet) RegisterAttributeSet(node xml.Node) {
name := node.Attr("name")
res := CompileSingleNode(node)
res.Compile(node)
style.AttributeSets[name] = res
}
开发者ID:xet7,项目名称:ratago,代码行数:6,代码来源:stylesheet.go
示例18: RegisterGlobalVariable
func (style *Stylesheet) RegisterGlobalVariable(node xml.Node) {
name := node.Attr("name")
_var := CompileSingleNode(node).(*Variable)
_var.Compile(node)
style.Variables[name] = _var
}
开发者ID:xet7,项目名称:ratago,代码行数:6,代码来源:stylesheet.go
示例19: 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
示例20: EvalMatch
// Returns true if the node matches the pattern
func (m *CompiledMatch) EvalMatch(node xml.Node, mode string, context *ExecutionContext) bool {
cur := node
//false if wrong mode
// #all is an XSLT 2.0 feature
if m.Template != nil && mode != m.Template.Mode && m.Template.Mode != "#all" {
return false
}
for i, step := range m.Steps {
switch step.Op {
case OP_END:
return true
case OP_ROOT:
if cur.NodeType() != xml.XML_DOCUMENT_NODE {
return false
}
case OP_ELEM:
if cur.NodeType() != xml.XML_ELEMENT_NODE {
return false
}
if step.Value != cur.Name() && step.Value != "*" {
return false
}
case OP_NS:
uri := ""
// m.Template.Node
if m.Template != nil {
uri = context.LookupNamespace(step.Value, m.Template.Node)
} else {
uri = context.LookupNamespace(step.Value, nil)
}
if uri != cur.Namespace() {
return false
}
case OP_ATTR:
if cur.NodeType() != xml.XML_ATTRIBUTE_NODE {
return false
}
if step.Value != cur.Name() && step.Value != "*" {
return false
}
case OP_TEXT:
if cur.NodeType() != xml.XML_TEXT_NODE && cur.NodeType() != xml.XML_CDATA_SECTION_NODE {
return false
}
case OP_COMMENT:
if cur.NodeType() != xml.XML_COMMENT_NODE {
return false
}
case OP_ALL:
if cur.NodeType() != xml.XML_ELEMENT_NODE {
return false
}
case OP_PI:
if cur.NodeType() != xml.XML_PI_NODE {
return false
}
case OP_NODE:
switch cur.NodeType() {
case xml.XML_ELEMENT_NODE, xml.XML_CDATA_SECTION_NODE, xml.XML_TEXT_NODE, xml.XML_COMMENT_NODE, xml.XML_PI_NODE:
// matches any of these node types
default:
return false
}
case OP_PARENT:
cur = cur.Parent()
if cur == nil {
return false
}
case OP_ANCESTOR:
next := m.Steps[i+1]
if next.Op != OP_ELEM {
return false
}
for {
cur = cur.Parent()
if cur == nil {
return false
}
if next.Value == cur.Name() {
break
}
}
case OP_PREDICATE:
// see test REC/5.2-16
// see test REC/5.2-22
evalFull := true
if context != nil {
prev := m.Steps[i-1]
if prev.Op == OP_PREDICATE {
prev = m.Steps[i-2]
}
if prev.Op == OP_ELEM || prev.Op == OP_ALL {
parent := cur.Parent()
sibs := context.ChildrenOf(parent)
var clen, pos int
for _, n := range sibs {
if n.NodePtr() == cur.NodePtr() {
//.........这里部分代码省略.........
开发者ID:xet7,项目名称:ratago,代码行数:101,代码来源:match.go
注:本文中的github.com/ThomsonReutersEikon/gokogiri/xml.Node类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论